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.

121 lines
3.2KB

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