Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

181 rinda
5.1KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Product;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  5. use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
  6. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  7. use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
  8. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  9. class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
  10. {
  11. protected bool $isJoinSections = false;
  12. protected bool $isJoinProductCategories = false;
  13. protected bool $isJoinProductFamilySectionProperties = false;
  14. protected bool $isJoinProducts = false;
  15. protected bool $isJoinQualityLabels = false;
  16. public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator)
  17. {
  18. parent::__construct($repository, 'pf', $paginator);
  19. }
  20. public function joinProductFamilySectionProperties(bool $addSelect = true): self
  21. {
  22. if (!$this->isJoinProductFamilySectionProperties) {
  23. $this->isJoinProductFamilySectionProperties = true;
  24. $this->leftJoin('.productFamilySectionProperties', 'pfsp');
  25. if ($addSelect) {
  26. $this->addSelect('pfsp');
  27. }
  28. }
  29. return $this;
  30. }
  31. public function joinQualityLabels(bool $addSelect = true): self
  32. {
  33. if (!$this->isJoinQualityLabels) {
  34. $this->isJoinQualityLabels = true;
  35. $this->leftJoin('.qualityLabels', 'pfql');
  36. if ($addSelect) {
  37. $this->addSelect('pfql');
  38. }
  39. }
  40. return $this;
  41. }
  42. public function joinSections(bool $addSelect = true): self
  43. {
  44. if (!$this->isJoinSections) {
  45. $this->isJoinSections = true;
  46. $this->leftJoin('pfsp.section', 'section');
  47. if ($addSelect) {
  48. $this->addSelect('section');
  49. }
  50. }
  51. return $this;
  52. }
  53. public function filterBySection(SectionInterface $section,bool $addSelectProductFamilySectionProperties = true)
  54. {
  55. $this->joinProductFamilySectionProperties($addSelectProductFamilySectionProperties);
  56. $this->andWhereSection('pfsp', $section);
  57. $this->andWhere('pfsp.status = 1');
  58. }
  59. public function filterByMerchantViaSection(MerchantInterface $merchant)
  60. {
  61. $this->joinProductFamilySectionProperties(false);
  62. $this->joinSections(false);
  63. $this->andWhereMerchant('section', $merchant);
  64. $this->andWhere('pfsp.status = 1');
  65. }
  66. public function selectCount(): self
  67. {
  68. return $this->select('count(pf.id)');
  69. }
  70. public function selectProductCategories(): self
  71. {
  72. $this->joinProductCategories();
  73. return $this->addSelect('pCategories');
  74. }
  75. public function filterLikeBehaviorStockCycle(string $behaviorStockCycle): self
  76. {
  77. return $this
  78. ->andWhere('.behaviorStockCycle LIKE :behaviorStockCycle')
  79. ->setParameter('behaviorStockCycle', $behaviorStockCycle);
  80. }
  81. public function filterByProductCategory(ProductCategoryInterface $category): self
  82. {
  83. $this->joinProductCategories();
  84. return $this
  85. ->andWhere(':category MEMBER OF .productCategories')
  86. ->setParameter('category', $category->getId());
  87. }
  88. public function filterByPropertyNoveltyExpirationDate($dateTime = null): self
  89. {
  90. if (is_null($dateTime)) {
  91. $dateTime = new \DateTime();
  92. }
  93. return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
  94. ->setParameter('now', $dateTime);
  95. }
  96. public function filterIsOrganicLabel(): self
  97. {
  98. return $this->andWhere('.propertyOrganicLabel IS NOT NULL');
  99. }
  100. public function filterIsNovelty()
  101. {
  102. return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
  103. ->setParameter('now', new \DateTime()) ;
  104. }
  105. public function filterByTerms($terms): self
  106. {
  107. $this->andWhere('.title LIKE :terms OR cat.title LIKE :terms');
  108. $this->setParameter(':terms', '%'.$terms.'%') ;
  109. return $this;
  110. }
  111. public function filterBySupplier($supplier): self
  112. {
  113. return $this->andWhereEqual('supplier', $supplier);
  114. }
  115. public function joinProductCategories(bool $addSelect = false): self
  116. {
  117. if (!$this->isJoinProductCategories) {
  118. $this->isJoinProductCategories = true;
  119. return $this
  120. ->leftJoin('.productCategories', 'cat')
  121. ->addSelect('cat')
  122. ;
  123. }
  124. return $this;
  125. }
  126. public function selectProducts(): self
  127. {
  128. $this->joinProducts();
  129. return $this->addSelect('products');
  130. }
  131. public function joinProducts(): self
  132. {
  133. if (!$this->isJoinProducts) {
  134. $this->isJoinProducts = true;
  135. return $this
  136. ->innerJoin('.products', 'pfp')
  137. ->addSelect('pfp')
  138. ;
  139. }
  140. return $this;
  141. }
  142. public function orderByPosition(): self
  143. {
  144. $this->orderBy('e.position', 'ASC');
  145. return $this;
  146. }
  147. }