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

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. //use SectionRepositoryQueryTrait;
  12. protected bool $isJoinProductCategories = false;
  13. protected bool $isJoinProductFamilySectionProperties = false;
  14. protected bool $isJoinProducts = false;
  15. public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator)
  16. {
  17. parent::__construct($repository, 'pf', $paginator);
  18. }
  19. public function joinProductFamilySectionProperties(bool $addSelect = true): self
  20. {
  21. if (!$this->isJoinProductFamilySectionProperties) {
  22. $this->isJoinProductFamilySectionProperties = true;
  23. $this->leftJoin('.productFamilySectionProperties', 'pfsp');
  24. if ($addSelect) {
  25. $this->addSelect('pfsp');
  26. }
  27. }
  28. return $this;
  29. }
  30. public function filterBySection(SectionInterface $section,bool $addSelectProductFamilySectionProperties = true)
  31. {
  32. $this->joinProductFamilySectionProperties($addSelectProductFamilySectionProperties);
  33. $this->andWhereSection('pfsp', $section);
  34. $this->andWhere('pfsp.status = 1');
  35. }
  36. public function selectCount(): self
  37. {
  38. return $this->select('count(pf.id)');
  39. }
  40. public function selectProductCategories(): self
  41. {
  42. $this->joinProductCategories();
  43. return $this->addSelect('pCategories');
  44. }
  45. public function filterLikeBehaviorStockCycle(string $behaviorStockCycle): self
  46. {
  47. return $this
  48. ->andWhere('.behaviorStockCycle LIKE :behaviorStockCycle')
  49. ->setParameter('behaviorStockCycle', $behaviorStockCycle);
  50. }
  51. public function filterByProductCategory(ProductCategoryInterface $category): self
  52. {
  53. $this->joinProductCategories();
  54. return $this
  55. ->andWhere(':category MEMBER OF .productCategories')
  56. ->setParameter('category', $category->getId());
  57. }
  58. public function filterByPropertyNoveltyExpirationDate($dateTime = null): self
  59. {
  60. if (is_null($dateTime)) {
  61. $dateTime = new \DateTime();
  62. }
  63. return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
  64. ->setParameter('now', $dateTime);
  65. }
  66. public function filterIsOrganicLabel(): self
  67. {
  68. return $this->andWhere('.propertyOrganicLabel IS NOT NULL');
  69. }
  70. public function filterIsNovelty()
  71. {
  72. return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
  73. ->setParameter('now', new \DateTime()) ;
  74. }
  75. public function filterByTerms($terms): self
  76. {
  77. $this->andWhere('.title LIKE :terms OR cat.title LIKE :terms');
  78. $this->setParameter(':terms', '%'.$terms.'%') ;
  79. return $this;
  80. }
  81. public function filterBySupplier($supplier): self
  82. {
  83. return $this->andWhereEqual('supplier', $supplier);
  84. }
  85. public function joinProductCategories(): self
  86. {
  87. if (!$this->isJoinProductCategories) {
  88. $this->isJoinProductCategories = true;
  89. return $this
  90. ->leftJoin('.productCategories', 'cat');
  91. //$query->addSelect('cat') ; ???
  92. }
  93. return $this;
  94. }
  95. public function selectProducts(): self
  96. {
  97. $this->joinProducts();
  98. return $this->addSelect('products');
  99. }
  100. public function joinProducts(): self
  101. {
  102. if (!$this->isJoinProducts) {
  103. $this->isJoinProducts = true;
  104. return $this
  105. ->innerJoin('.products', 'pfp');
  106. // $query->addSelect('pfp') ; ?????
  107. }
  108. return $this;
  109. }
  110. public function orderByPosition(): self
  111. {
  112. $this->orderBy('e.position', 'ASC');
  113. return $this;
  114. }
  115. }