Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

61 lines
1.6KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Reduction;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
  5. use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
  6. use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
  7. use Lc\SovBundle\Model\User\UserInterface;
  8. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  9. class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery
  10. {
  11. use SectionRepositoryQueryTrait;
  12. protected $isJoinUsers = false;
  13. public function __construct(ReductionCreditRepository $repository, PaginatorInterface $paginator)
  14. {
  15. parent::__construct($repository, 'reductionCredit', $paginator);
  16. }
  17. public function filterByUser(UserInterface $user)
  18. {
  19. return $this
  20. ->andWhere(':user MEMBER OF .users')
  21. ->setParameter('user', $user);
  22. }
  23. public function filterByOwner(UserInterface $user)
  24. {
  25. return $this
  26. ->andWhere('.owner = :user')
  27. ->setParameter('user', $user);
  28. }
  29. public function filterByType(string $type = ReductionCreditModel::TYPE_CREDIT)
  30. {
  31. return $this
  32. ->andWhere('.type = :type')
  33. ->setParameter('type', $type);
  34. }
  35. public function filterInactive()
  36. {
  37. $this->joinUsers();
  38. return $this->having('COUNT(users.id) = 0');
  39. }
  40. public function filterActive()
  41. {
  42. $this->joinUsers();
  43. return $this->having('COUNT(users.id) > 0');
  44. }
  45. public function joinUsers()
  46. {
  47. return $this->leftJoin('.users', 'users');
  48. }
  49. }