|
- <?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\Model\Section\SectionInterface;
- use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
- use Lc\SovBundle\Repository\AbstractRepositoryQuery;
-
- class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
- {
- protected bool $isJoinSections = false;
- protected bool $isJoinProductCategories = false;
- protected bool $isJoinProductFamilySectionProperties = false;
- protected bool $isJoinProducts = false;
- protected bool $isJoinQualityLabels = false;
-
- public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'productFamily', $paginator);
- }
-
- public function joinProductFamilySectionProperties(bool $addSelect = true): self
- {
- if (!$this->isJoinProductFamilySectionProperties) {
- $this->isJoinProductFamilySectionProperties = true;
-
- $this->leftJoin('.productFamilySectionProperties', 'productFamilySectionProperties');
- if ($addSelect) {
- //NB : Ici le select est en commentaire car si il est actif doctrine n'hydrate pas correectement ProductFamilySectionProperties (si filtre sur section les ProductFamilySectionProperties des autres sections ne sont pas chargé et ça peut être problématique pr la gestion des stocks)
- //$this->addSelect('productFamilySectionProperties');
- }
- }
- return $this;
- }
-
- public function joinQualityLabels(bool $addSelect = true): self
- {
- if (!$this->isJoinQualityLabels) {
- $this->isJoinQualityLabels = true;
-
- $this->leftJoin('.qualityLabels', 'qualityLabels');
- if ($addSelect) {
- $this->addSelect('qualityLabels');
- }
- }
- return $this;
- }
-
- public function joinSections(bool $addSelect = true): self
- {
- if (!$this->isJoinSections) {
- $this->isJoinSections = true;
-
- $this->leftJoin('productFamilySectionProperties.section', 'section');
- if ($addSelect) {
- $this->addSelect('section');
- }
- }
- return $this;
- }
-
- public function filterBySection(SectionInterface $section, bool $addSelectProductFamilySectionProperties = true)
- {
- $this->joinProductFamilySectionProperties($addSelectProductFamilySectionProperties);
- $this->andWhereSection('productFamilySectionProperties', $section);
- $this->andWhere('productFamilySectionProperties.status = 1');
- }
-
- public function filterByMerchantViaSection(MerchantInterface $merchant)
- {
- $this->joinProductFamilySectionProperties(false);
- $this->joinSections(false);
- $this->andWhereMerchant('section', $merchant);
- $this->andWhere('productFamilySectionProperties.status = 1');
- }
-
-
- public function selectCount(): self
- {
- return $this->select('count(productFamily.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 filterByProductCategoryArray(Array $categoryArray): self
- {
- $this->joinProductCategories();
- return $this
- ->andWhere(':categoryArray MEMBER OF .productCategories')
- ->setParameter('categoryArray', $categoryArray);
- }
-
-
- 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 productCategories.title LIKE :terms');
- $this->setParameter(':terms', '%' . $terms . '%');
- return $this;
- }
-
- public function filterBySupplier($supplier): self
- {
- return $this->andWhereEqual('supplier', $supplier);
- }
-
- public function joinProductCategories(bool $addSelect = false): self
- {
- if (!$this->isJoinProductCategories) {
- $this->isJoinProductCategories = true;
-
- $this->leftJoin('.productCategories', 'productCategories');
- if ($addSelect) {
- $this->addSelect('productCategories');
- }
- return $this;
- }
- return $this;
- }
-
- public function selectProducts(): self
- {
- return $this->joinProducts(true);
- }
-
- public function joinProducts(bool $addSelect = true): self
- {
- if (!$this->isJoinProducts) {
- $this->isJoinProducts = true;
-
- $this->innerJoin('.products', 'products');
- if ($addSelect) {
- $this->addSelect('products');
- }
- }
- return $this;
- }
-
- public function orderByPosition(): self
- {
- $this->orderBy('e.position', 'ASC');
- return $this;
- }
-
- }
|