|
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Reduction;
-
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
- use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
- use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Repository\AbstractRepositoryQuery;
-
- class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery
- {
- use SectionRepositoryQueryTrait;
-
- protected $isJoinUsers = false;
-
- public function __construct(ReductionCreditRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'r', $paginator);
- }
-
- public function filterByUser(UserInterface $user)
- {
- return $this
- ->andWhere(':user MEMBER OF .users')
- ->setParameter('user', $user);
- }
-
- public function filterByOwner(UserInterface $user)
- {
- return $this
- ->andWhere('.owner = :user')
- ->setParameter('user', $user);
- }
-
- public function filterByType(string $type = ReductionCreditModel::TYPE_CREDIT)
- {
- return $this
- ->andWhere('.type = :type')
- ->setParameter('type', $type);
- }
-
- public function filterInactive()
- {
- $this->joinUsers();
- return $this->having('COUNT(users.id) = 0');
- }
-
- public function filterActive()
- {
- $this->joinUsers();
- return $this->having('COUNT(users.id) > 0');
- }
-
- public function joinUsers()
- {
- return $this->leftJoin('.users', 'users');
- }
- }
|