|
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Reduction;
-
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
- use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
- use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Repository\AbstractRepositoryQuery;
-
- class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
- {
- protected bool $isJoinProductFamilies;
- protected bool $isJoinProductFamily;
- protected bool $isJoinProductCategories;
- use SectionRepositoryQueryTrait;
-
- public function __construct(ReductionCatalogRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'r', $paginator);
- }
-
- public function joinProductFamilies()
- {
- if (!$this->isJoinProductFamilies) {
- $this->isJoinProductFamilies = true;
-
- return $this
- ->leftJoin('.productFamilies', 'pfs');
- //->addSelect('pfs') ;
- }
- return $this;
- }
-
- public function joinProductFamily()
- {
- if (!$this->isJoinProductFamily) {
- $this->isJoinProductFamily = true;
-
- return $this
- ->leftJoin('.productFamily', 'pf');
- //->addSelect('pf') ;
- }
- return $this;
- }
-
- public function joinProductCategories()
- {
- if (!$this->isJoinProductCategories) {
- $this->isJoinProductCategories = true;
-
- return $this
- ->leftJoin('.productCategories', 'pcs');
- //->addSelect('pcs') ;
- }
- return $this;
- }
-
-
- public function filterProductFamily(ProductFamilyInterface $productFamily)
- {
- return $this
- ->andWhere('.productFamily = :productFamily')
- ->setParameter(':productFamily', $productFamily);
- }
-
- public function filterConditionDate()
- {
- return $this
- ->andWhere('e.permanent = 1 OR (e.dateStart <= :now AND e.dateEnd >= :now)')
- ->setParameter(':now', new \DateTime());
- }
-
- public function filterConditionUser(UserInterface $user = null)
- {
- if ($user) {
- return $this
- ->andWhere(':user MEMBER OF e.users OR e.users is empty')
- ->setParameter('user', $user);
- } else {
- return $this
- ->andWhere('e.users is empty');
- }
- }
-
- public function filterConditionGroupUser(UserInterface $user = null)
- {
- if ($user) {
- return $this
- ->andWhere(':groupUser MEMBER OF e.groupUsers OR e.groupUsers is empty')
- ->setParameter('groupUser', $user->getGroupUsers());
- } else {
- return $this
- ->andWhere('e.groupUsers is empty');
- }
- }
-
- public function filterConditionProductFamilies(array $productFamilies)
- {
- $this->joinProductFamilies();
- $this->joinProductFamily();
- return $this
- ->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty')
- ->setParameter('productFamily', $productFamilies);
- }
-
- public function filterConditionProductFamily(ProductFamilyInterface $productFamily)
- {
- $this->joinProductFamilies();
- $this->joinProductFamily();
- return $this
- ->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty')
- ->setParameter('productFamily', $productFamily);
- }
-
- public function filterConditionProductCategories(array $productCategories)
- {
- $this->joinProductCategories();
- return $this
- ->andWhere(':productCategory MEMBER OF e.productCategories OR e.productCategories is empty')
- ->setParameter('productCategory', $productCategories);
- }
-
-
- }
|