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.

122 lines
3.3KB

  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\Repository\SectionRepositoryQueryTrait;
  7. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  8. class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
  9. {
  10. use SectionRepositoryQueryTrait;
  11. protected bool $isJoinProductCategories = false;
  12. protected bool $isJoinProducts = false;
  13. public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator)
  14. {
  15. parent::__construct($repository, 'r', $paginator);
  16. }
  17. public function selectCount(): self
  18. {
  19. return $this->select('count(r.id)');
  20. }
  21. public function selectProductCategories(): self
  22. {
  23. $this->joinProductCategories();
  24. return $this->addSelect('pCategories');
  25. }
  26. public function filterLikeBehaviorStockCycle(string $behaviorStockCycle): self
  27. {
  28. return $this
  29. ->andWhere('.behaviorStockCycle LIKE :behaviorStockCycle')
  30. ->setParameter('behaviorStockCycle', $behaviorStockCycle);
  31. }
  32. public function filterByProductCategory(ProductCategoryInterface $category): self
  33. {
  34. $this->joinProductCategories();
  35. return $this
  36. ->andWhere(':category MEMBER OF .productCategories')
  37. ->setParameter('category', $category->getId());
  38. }
  39. public function filterByPropertyNoveltyExpirationDate($dateTime = null): self
  40. {
  41. if (is_null($dateTime)) {
  42. $dateTime = new \DateTime();
  43. }
  44. return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
  45. ->setParameter('now', $dateTime);
  46. }
  47. public function filterIsOrganicLabel(): self
  48. {
  49. return $this->andWhere('.propertyOrganicLabel IS NOT NULL');
  50. }
  51. public function filterIsNovelty()
  52. {
  53. return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
  54. ->setParameter('now', new \DateTime()) ;
  55. }
  56. public function filterByTerms($terms): self
  57. {
  58. $this->andWhere('.title LIKE :terms OR cat.title LIKE :terms');
  59. $this->setParameter(':terms', '%'.$terms.'%') ;
  60. return $this;
  61. }
  62. public function filterBySupplier($supplier): self
  63. {
  64. return $this->andWhereEqual('supplier', $supplier);
  65. }
  66. public function joinProductCategories(): self
  67. {
  68. if (!$this->isJoinProductCategories) {
  69. $this->isJoinProductCategories = true;
  70. return $this
  71. ->leftJoin('.productCategories', 'cat');
  72. //$query->addSelect('cat') ; ???
  73. }
  74. return $this;
  75. }
  76. public function selectProducts(): self
  77. {
  78. $this->joinProducts();
  79. return $this->addSelect('products');
  80. }
  81. public function joinProducts(): self
  82. {
  83. if (!$this->isJoinProducts) {
  84. $this->isJoinProducts = true;
  85. return $this
  86. ->innerJoin('.products', 'pfp');
  87. // $query->addSelect('pfp') ; ?????
  88. }
  89. return $this;
  90. }
  91. public function orderByPosition(): self
  92. {
  93. $this->orderBy('e.position', 'ASC');
  94. return $this;
  95. }
  96. }