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.

107 lines
2.8KB

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