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.

ProductFamilyRepositoryQuery.php 5.9KB

3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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, 'productFamily', $paginator);
  19. }
  20. public function joinProductFamilySectionProperties(bool $addSelect = true): self
  21. {
  22. if (!$this->isJoinProductFamilySectionProperties) {
  23. $this->isJoinProductFamilySectionProperties = true;
  24. $this->leftJoin('.productFamilySectionProperties', 'productFamilySectionProperties');
  25. if ($addSelect) {
  26. //NB : Ici le select est en commentaire car si il est actif doctrine n'hydrate pas correectement ProductFamilySectionProperties (si filtre sur section les ProductFamilySectionProperties des autres sections ne sont pas chargé et ça peut être problématique pr la gestion des stocks)
  27. //$this->addSelect('productFamilySectionProperties');
  28. }
  29. }
  30. return $this;
  31. }
  32. public function joinQualityLabels(bool $addSelect = true): self
  33. {
  34. if (!$this->isJoinQualityLabels) {
  35. $this->isJoinQualityLabels = true;
  36. $this->leftJoin('.qualityLabels', 'qualityLabels');
  37. if ($addSelect) {
  38. $this->addSelect('qualityLabels');
  39. }
  40. }
  41. return $this;
  42. }
  43. public function joinSections(bool $addSelect = true): self
  44. {
  45. if (!$this->isJoinSections) {
  46. $this->isJoinSections = true;
  47. $this->leftJoin('productFamilySectionProperties.section', 'section');
  48. if ($addSelect) {
  49. $this->addSelect('section');
  50. }
  51. }
  52. return $this;
  53. }
  54. public function filterBySection(SectionInterface $section, bool $addSelectProductFamilySectionProperties = true)
  55. {
  56. $this->joinProductFamilySectionProperties($addSelectProductFamilySectionProperties);
  57. $this->andWhereSection('productFamilySectionProperties', $section);
  58. $this->andWhere('productFamilySectionProperties.status = 1');
  59. }
  60. public function filterByMerchantViaSection(MerchantInterface $merchant)
  61. {
  62. $this->joinProductFamilySectionProperties(false);
  63. $this->joinSections(false);
  64. $this->andWhereMerchant('section', $merchant);
  65. $this->andWhere('productFamilySectionProperties.status = 1');
  66. }
  67. public function selectCount(): self
  68. {
  69. return $this->select('count(productFamily.id)');
  70. }
  71. public function selectProductCategories(): self
  72. {
  73. $this->joinProductCategories();
  74. return $this->addSelect('pCategories');
  75. }
  76. public function filterLikeBehaviorStockCycle(string $behaviorStockCycle): self
  77. {
  78. return $this
  79. ->andWhere('.behaviorStockCycle LIKE :behaviorStockCycle')
  80. ->setParameter('behaviorStockCycle', $behaviorStockCycle);
  81. }
  82. public function filterByProductCategory(ProductCategoryInterface $category): self
  83. {
  84. $this->joinProductCategories();
  85. return $this
  86. ->andWhere(':category MEMBER OF .productCategories')
  87. ->setParameter('category', $category->getId());
  88. }
  89. public function filterByProductCategoryArray(Array $categoryArray): self
  90. {
  91. $this->joinProductCategories();
  92. return $this
  93. ->andWhere(':categoryArray MEMBER OF .productCategories')
  94. ->setParameter('categoryArray', $categoryArray);
  95. }
  96. public function filterByPropertyNoveltyExpirationDate($dateTime = null): self
  97. {
  98. if (is_null($dateTime)) {
  99. $dateTime = new \DateTime();
  100. }
  101. return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
  102. ->setParameter('now', $dateTime);
  103. }
  104. public function filterIsOrganicLabel(): self
  105. {
  106. return $this->andWhere('.propertyOrganicLabel IS NOT NULL');
  107. }
  108. public function filterIsNovelty()
  109. {
  110. return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
  111. ->setParameter('now', new \DateTime());
  112. }
  113. public function filterByTerms($terms): self
  114. {
  115. $this->andWhere('.title LIKE :terms OR productCategories.title LIKE :terms');
  116. $this->setParameter(':terms', '%' . $terms . '%');
  117. return $this;
  118. }
  119. public function filterBySupplier($supplier): self
  120. {
  121. return $this->andWhereEqual('supplier', $supplier);
  122. }
  123. public function joinProductCategories(bool $addSelect = false): self
  124. {
  125. if (!$this->isJoinProductCategories) {
  126. $this->isJoinProductCategories = true;
  127. $this->leftJoin('.productCategories', 'productCategories');
  128. if ($addSelect) {
  129. $this->addSelect('productCategories');
  130. }
  131. return $this;
  132. }
  133. return $this;
  134. }
  135. public function selectProducts(): self
  136. {
  137. return $this->joinProducts(true);
  138. }
  139. public function joinProducts(bool $addSelect = true): self
  140. {
  141. if (!$this->isJoinProducts) {
  142. $this->isJoinProducts = true;
  143. $this->innerJoin('.products', 'products');
  144. if ($addSelect) {
  145. $this->addSelect('products');
  146. }
  147. }
  148. return $this;
  149. }
  150. public function orderByPosition(): self
  151. {
  152. $this->orderBy('e.position', 'ASC');
  153. return $this;
  154. }
  155. }