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

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. }