You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReductionCreditRepositoryQuery.php 1.6KB

3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\SovBundle\Model\User\UserInterface;
  7. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  8. class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery
  9. {
  10. use MerchantRepositoryQueryTrait;
  11. // @TODO : à utiliser
  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. }