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.

ReductionCatalogRepositoryQuery.php 4.6KB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Reduction;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  5. use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
  6. use Lc\SovBundle\Model\User\UserInterface;
  7. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  8. class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
  9. {
  10. protected bool $isJoinProductFamilies = false;
  11. protected bool $isJoinProductFamily = false;
  12. protected bool $isJoinProductCategories = false;
  13. protected bool $isJoinUsers = false;
  14. protected bool $isJoinGroupUsers = false;
  15. use MerchantRepositoryQueryTrait;
  16. public function __construct(ReductionCatalogRepository $repository, PaginatorInterface $paginator)
  17. {
  18. parent::__construct($repository, 'r', $paginator);
  19. }
  20. public function joinUsers()
  21. {
  22. if (!$this->isJoinUsers) {
  23. $this->isJoinUsers = true;
  24. return $this
  25. ->leftJoin('.users', 'pf_users')
  26. ->addSelect('pf_users') ;
  27. }
  28. return $this;
  29. }
  30. public function joinGroupUsers()
  31. {
  32. if (!$this->isJoinGroupUsers) {
  33. $this->isJoinGroupUsers = true;
  34. return $this
  35. ->leftJoin('.groupUsers', 'groupUsers')
  36. ->addSelect('groupUsers') ;
  37. }
  38. return $this;
  39. }
  40. public function joinProductFamilies()
  41. {
  42. if (!$this->isJoinProductFamilies) {
  43. $this->isJoinProductFamilies = true;
  44. return $this
  45. ->leftJoin('.productFamilies', 'productFamilies')
  46. ->addSelect('productFamilies') ;
  47. }
  48. return $this;
  49. }
  50. public function joinProductFamily()
  51. {
  52. if (!$this->isJoinProductFamily) {
  53. $this->isJoinProductFamily = true;
  54. return $this
  55. ->leftJoin('.productFamily', 'productFamily')
  56. ->addSelect('productFamily') ;
  57. }
  58. return $this;
  59. }
  60. public function joinProductCategories()
  61. {
  62. if (!$this->isJoinProductCategories) {
  63. $this->isJoinProductCategories = true;
  64. return $this
  65. ->leftJoin('.productCategories', 'productCategories')
  66. ->addSelect('productCategories') ;
  67. }
  68. return $this;
  69. }
  70. public function filterProductFamily(ProductFamilyInterface $productFamily)
  71. {
  72. return $this
  73. ->andWhere('.productFamily = :productFamily')
  74. ->setParameter(':productFamily', $productFamily);
  75. }
  76. public function filterConditionDate()
  77. {
  78. return $this
  79. ->andWhere('.permanent = 1 OR ( .dateStart <= :now AND .dateEnd >= :now)')
  80. ->setParameter(':now', new \DateTime());
  81. }
  82. public function filterConditionUser(UserInterface $user = null)
  83. {
  84. $this->joinUsers();
  85. if ($user) {
  86. return $this
  87. ->andWhere(':user MEMBER OF .users OR .users is empty')
  88. ->setParameter('user', $user);
  89. } else {
  90. return $this
  91. ->andWhere('.users is empty');
  92. }
  93. }
  94. public function filterConditionGroupUser(UserInterface $user = null)
  95. {
  96. $this->joinGroupUsers();
  97. if ($user) {
  98. return $this
  99. ->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
  100. ->setParameter('groupUser', $user->getGroupUsers());
  101. } else {
  102. return $this
  103. ->andWhere('.groupUsers is empty');
  104. }
  105. }
  106. public function filterConditionProductFamilies(array $productFamilies)
  107. {
  108. $this->joinProductFamilies();
  109. return $this
  110. ->andWhere(':productFamilies MEMBER OF .productFamilies OR .productFamilies is empty')
  111. ->setParameter('productFamilies', $productFamilies);
  112. }
  113. public function filterConditionProductFamily(ProductFamilyInterface $productFamily)
  114. {
  115. $this->joinProductFamily();
  116. return $this
  117. ->andWhere(':productFamily MEMBER OF .productFamily OR .productFamily is empty')
  118. ->setParameter('productFamily', $productFamily);
  119. }
  120. public function filterConditionProductCategories(array $productCategories)
  121. {
  122. $this->joinProductCategories();
  123. return $this
  124. ->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
  125. ->setParameter('productCategory', $productCategories);
  126. }
  127. }