|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Product;
-
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
- use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
- use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
- use Lc\SovBundle\Repository\AbstractRepositoryQuery;
-
- class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
- {
- use SectionRepositoryQueryTrait;
-
- protected bool $isJoinProductCategories = false;
- protected bool $isJoinProducts = false;
-
- public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'r', $paginator);
- }
-
- public function selectCount(): self
- {
- return $this->select('count(r.id)');
- }
-
- public function selectProductCategories(): self
- {
- $this->joinProductCategories();
-
- return $this->addSelect('pCategories');
- }
-
- public function filterLikeBehaviorStockCycle(string $behaviorStockCycle): self
- {
- return $this
- ->andWhere('.behaviorStockCycle LIKE :behaviorStockCycle')
- ->setParameter('behaviorStockCycle', $behaviorStockCycle);
- }
-
- public function filterByProductCategory(ProductCategoryInterface $category): self
- {
- $this->joinProductCategories();
- return $this
- ->andWhere(':category MEMBER OF .productCategories')
- ->setParameter('category', $category->getId());
- }
-
-
- public function filterByPropertyNoveltyExpirationDate($dateTime = null): self
- {
- if (is_null($dateTime)) {
- $dateTime = new \DateTime();
- }
-
- return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
- ->setParameter('now', $dateTime);
- }
-
- public function filterIsOrganicLabel(): self
- {
- return $this->andWhere('.propertyOrganicLabel IS NOT NULL');
- }
-
- public function filterIsNovelty()
- {
- return $this->andWhere(':now <= .propertyNoveltyExpirationDate')
- ->setParameter('now', new \DateTime()) ;
- }
-
- public function filterByTerms($terms): self
- {
- $this->andWhere('.title LIKE :terms OR cat.title LIKE :terms');
- $this->setParameter(':terms', '%'.$terms.'%') ;
- return $this;
- }
-
- public function filterBySupplier($supplier): self
- {
- return $this->andWhereEqual('supplier', $supplier);
- }
-
- public function joinProductCategories(): self
- {
- if (!$this->isJoinProductCategories) {
- $this->isJoinProductCategories = true;
-
- return $this
- ->leftJoin('.productCategories', 'cat');
- //$query->addSelect('cat') ; ???
- }
- return $this;
- }
-
- public function selectProducts(): self
- {
- $this->joinProducts();
-
- return $this->addSelect('products');
- }
-
- public function joinProducts(): self
- {
- if (!$this->isJoinProducts) {
- $this->isJoinProducts = true;
-
- return $this
- ->innerJoin('.products', 'pfp');
- // $query->addSelect('pfp') ; ?????
- }
- return $this;
- }
-
- public function orderByPosition(): self
- {
- $this->orderBy('e.position', 'ASC');
- return $this;
- }
-
- }
|