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.

127 lines
3.9KB

  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\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
  7. use Lc\SovBundle\Model\User\UserInterface;
  8. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  9. class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
  10. {
  11. protected bool $isJoinProductFamilies = false;
  12. protected bool $isJoinProductFamily = false;
  13. protected bool $isJoinProductCategories = false;
  14. use SectionRepositoryQueryTrait;
  15. public function __construct(ReductionCatalogRepository $repository, PaginatorInterface $paginator)
  16. {
  17. parent::__construct($repository, 'r', $paginator);
  18. }
  19. public function joinProductFamilies()
  20. {
  21. if (!$this->isJoinProductFamilies) {
  22. $this->isJoinProductFamilies = true;
  23. return $this
  24. ->leftJoin('.productFamilies', 'pfs');
  25. //->addSelect('pfs') ;
  26. }
  27. return $this;
  28. }
  29. public function joinProductFamily()
  30. {
  31. if (!$this->isJoinProductFamily) {
  32. $this->isJoinProductFamily = true;
  33. return $this
  34. ->leftJoin('.productFamily', 'pf');
  35. //->addSelect('pf') ;
  36. }
  37. return $this;
  38. }
  39. public function joinProductCategories()
  40. {
  41. if (!$this->isJoinProductCategories) {
  42. $this->isJoinProductCategories = true;
  43. return $this
  44. ->leftJoin('.productCategories', 'pcs');
  45. //->addSelect('pcs') ;
  46. }
  47. return $this;
  48. }
  49. public function filterProductFamily(ProductFamilyInterface $productFamily)
  50. {
  51. return $this
  52. ->andWhere('.productFamily = :productFamily')
  53. ->setParameter(':productFamily', $productFamily);
  54. }
  55. public function filterConditionDate()
  56. {
  57. return $this
  58. ->andWhere('.permanent = 1 OR ( .dateStart <= :now AND .dateEnd >= :now)')
  59. ->setParameter(':now', new \DateTime());
  60. }
  61. public function filterConditionUser(UserInterface $user = null)
  62. {
  63. if ($user) {
  64. return $this
  65. ->andWhere(':user MEMBER OF .users OR .users is empty')
  66. ->setParameter('user', $user);
  67. } else {
  68. return $this
  69. ->andWhere('.users is empty');
  70. }
  71. }
  72. public function filterConditionGroupUser(UserInterface $user = null)
  73. {
  74. if ($user) {
  75. return $this
  76. ->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
  77. ->setParameter('groupUser', $user->getGroupUsers());
  78. } else {
  79. return $this
  80. ->andWhere('.groupUsers is empty');
  81. }
  82. }
  83. public function filterConditionProductFamilies(array $productFamilies)
  84. {
  85. $this->joinProductFamilies();
  86. $this->joinProductFamily();
  87. return $this
  88. ->andWhere(':productFamilies MEMBER OF .productFamilies OR .productFamilies is empty')
  89. ->setParameter('productFamilies', $productFamilies);
  90. }
  91. public function filterConditionProductFamily(ProductFamilyInterface $productFamily)
  92. {
  93. $this->joinProductFamilies();
  94. $this->joinProductFamily();
  95. return $this
  96. ->andWhere(':productFamily MEMBER OF .productFamilies OR .productFamilies is empty')
  97. ->setParameter('productFamily', $productFamily);
  98. }
  99. public function filterConditionProductCategories(array $productCategories)
  100. {
  101. $this->joinProductCategories();
  102. return $this
  103. ->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
  104. ->setParameter('productCategory', $productCategories);
  105. }
  106. }