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 6.7KB

3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
3 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Product;
  3. use Doctrine\ORM\Query\Expr;
  4. use Knp\Component\Pager\PaginatorInterface;
  5. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  6. use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
  7. use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
  8. use Lc\CaracoleBundle\Model\Product\QualityLabel;
  9. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  10. use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
  11. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  12. class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
  13. {
  14. protected bool $isJoinSections = false;
  15. protected bool $isJoinProductCategories = false;
  16. protected bool $isJoinProductFamilySectionProperties = false;
  17. protected bool $isJoinProducts = false;
  18. protected bool $isJoinQualityLabels = false;
  19. public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator)
  20. {
  21. parent::__construct($repository, 'productFamily', $paginator);
  22. }
  23. public function resetRelationsJoin(): void
  24. {
  25. $this->isJoinSections = false;
  26. $this->isJoinProductCategories = false;
  27. $this->isJoinProductFamilySectionProperties = false;
  28. $this->isJoinProducts = false;
  29. $this->isJoinQualityLabels = false;
  30. }
  31. public function joinProductFamilySectionProperties(bool $addSelect = true): self
  32. {
  33. if (!$this->isJoinProductFamilySectionProperties) {
  34. $this->isJoinProductFamilySectionProperties = true;
  35. $this->leftJoin('.productFamilySectionProperties', 'productFamilySectionProperties');
  36. if ($addSelect) {
  37. //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)
  38. //$this->addSelect('productFamilySectionProperties');
  39. }
  40. }
  41. return $this;
  42. }
  43. public function joinQualityLabels(bool $addSelect = true): self
  44. {
  45. if (!$this->isJoinQualityLabels) {
  46. $this->isJoinQualityLabels = true;
  47. $this->leftJoin('.qualityLabels', 'qualityLabels');
  48. if ($addSelect) {
  49. $this->addSelect('qualityLabels');
  50. }
  51. }
  52. return $this;
  53. }
  54. public function joinSections(bool $addSelect = true): self
  55. {
  56. if (!$this->isJoinSections) {
  57. $this->isJoinSections = true;
  58. $this->leftJoin('productFamilySectionProperties.section', 'section');
  59. if ($addSelect) {
  60. $this->addSelect('section');
  61. }
  62. }
  63. return $this;
  64. }
  65. public function filterBySection(SectionInterface $section, bool $addSelectProductFamilySectionProperties = true)
  66. {
  67. $this->joinProductFamilySectionProperties($addSelectProductFamilySectionProperties);
  68. $this->andWhereSection('productFamilySectionProperties', $section);
  69. $this->andWhere('productFamilySectionProperties.status = 1');
  70. }
  71. public function filterByMerchantViaSection(MerchantInterface $merchant)
  72. {
  73. $this->joinProductFamilySectionProperties(false);
  74. $this->joinSections(false);
  75. $this->andWhereMerchant('section', $merchant);
  76. //$this->andWhere('productFamilySectionProperties.status = 1');
  77. }
  78. public function selectCount(): self
  79. {
  80. return $this->select('count(productFamily.id)');
  81. }
  82. public function selectProductCategories(): self
  83. {
  84. $this->joinProductCategories();
  85. return $this->addSelect('pCategories');
  86. }
  87. public function filterLikeBehaviorStockCycle(string $behaviorStockCycle): self
  88. {
  89. return $this
  90. ->andWhere('.behaviorStockCycle LIKE :behaviorStockCycle')
  91. ->setParameter('behaviorStockCycle', $behaviorStockCycle);
  92. }
  93. public function filterByProductCategory(ProductCategoryInterface $category): self
  94. {
  95. $this->joinProductCategories();
  96. return $this
  97. ->andWhere(':category MEMBER OF .productCategories')
  98. ->setParameter('category', $category->getId());
  99. }
  100. public function filterByProductCategoryArray(array $categoryArray): self
  101. {
  102. $this->joinProductCategories();
  103. return $this
  104. ->andWhere(':categoryArray MEMBER OF .productCategories')
  105. ->setParameter('categoryArray', $categoryArray);
  106. }
  107. public function filterByPropertyNoveltyExpirationDate($dateTime = null): self
  108. {
  109. if (is_null($dateTime)) {
  110. $dateTime = new \DateTime();
  111. }
  112. return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
  113. ->setParameter('now', $dateTime);
  114. }
  115. public function filterIsOrganicLabel(): self
  116. {
  117. return $this->innerJoin('.qualityLabels', 'qualityLabel')
  118. ->andWhere('qualityLabel.devAlias IN (:organicLabels)')
  119. ->setParameter(':organicLabels', ProductFamilyModel::$organicLabels);
  120. }
  121. public function filterIsNovelty()
  122. {
  123. return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
  124. ->setParameter('now', new \DateTime());
  125. }
  126. public function filterByTerms($terms): self
  127. {
  128. $this->andWhere('.title LIKE :terms OR productCategories.title LIKE :terms');
  129. $this->setParameter(':terms', '%' . $terms . '%');
  130. return $this;
  131. }
  132. public function filterBySupplier($supplier): self
  133. {
  134. return $this->andWhereEqual('supplier', $supplier);
  135. }
  136. public function joinProductCategories(bool $addSelect = true): self
  137. {
  138. if (!$this->isJoinProductCategories) {
  139. $this->isJoinProductCategories = true;
  140. $this->leftJoin('.productCategories', 'productCategories');
  141. if ($addSelect) {
  142. $this->addSelect('productCategories');
  143. }
  144. return $this;
  145. }
  146. return $this;
  147. }
  148. public function selectProducts(): self
  149. {
  150. return $this->joinProducts(true);
  151. }
  152. public function joinProducts(bool $addSelect = true): self
  153. {
  154. if (!$this->isJoinProducts) {
  155. $this->isJoinProducts = true;
  156. $this->innerJoin('.products', 'products');
  157. if ($addSelect) {
  158. // Décommenté sinon doctrine n'hydrate pas correctement les produits liés au ProductFamily (exemple : un seul sur deux)
  159. // $this->addSelect('products');
  160. }
  161. }
  162. return $this;
  163. }
  164. public function orderByPosition(): self
  165. {
  166. $this->orderBy('e.position', 'ASC');
  167. return $this;
  168. }
  169. }