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.

82 lines
2.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\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 joinProductCategories(): self
  15. {
  16. if (!$this->isJoinProductCategories) {
  17. $this->isJoinProductCategories = true;
  18. return $this
  19. ->leftJoin('.productCategories', 'cat');
  20. //$query->addSelect('cat') ; ???
  21. }
  22. return $this;
  23. }
  24. public function joinProducts(): self
  25. {
  26. if (!$this->isJoinProducts) {
  27. $this->isJoinProducts = true;
  28. return $this
  29. ->innerJoin('.products', 'pfp');
  30. // $query->addSelect('pfp') ; ?????
  31. }
  32. return $this;
  33. }
  34. public function orderByPosition(): self
  35. {
  36. $this->orderBy('e.position', 'ASC');
  37. return $this;
  38. }
  39. public function filterByProductCategory(ProductCategoryInterface $category): self
  40. {
  41. $this->joinProductCategories();
  42. return $this
  43. ->andWhere(':category MEMBER OF .productCategories')
  44. ->setParameter('category', $category->getId());
  45. }
  46. public function filterByPropertyNoveltyExpirationDate($dateTime = null): self
  47. {
  48. if (is_null($dateTime)) {
  49. $dateTime = new \DateTime();
  50. }
  51. return $this->andWhere(':now <= e.propertyNoveltyExpirationDate')
  52. ->setParameter('now', $dateTime);
  53. }
  54. public function filterIsOrganicLabel(): self
  55. {
  56. return $this->andWhere('.propertyOrganicLabel IS NOT NULL');
  57. }
  58. public function filterByTerms($terms): self
  59. {
  60. $this->andWhere('.title LIKE :terms OR cat.title LIKE :terms');
  61. $this->setParameter(':terms', '%'.$terms.'%') ;
  62. return $this;
  63. }
  64. }