|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?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 = false;
- protected bool $isJoinProductFamily = false;
- protected bool $isJoinProductCategories = false;
- protected bool $isJoinUsers = false;
- protected bool $isJoinGroupUsers = false;
-
- use SectionRepositoryQueryTrait;
-
- public function __construct(ReductionCatalogRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'r', $paginator);
- }
-
- public function joinUsers()
- {
- if (!$this->isJoinUsers) {
- $this->isJoinUsers = true;
-
- return $this
- ->leftJoin('.users', 'pf_users')
- ->addSelect('pf_users') ;
- }
- return $this;
- }
-
- public function joinGroupUsers()
- {
- if (!$this->isJoinGroupUsers) {
- $this->isJoinGroupUsers = true;
-
- return $this
- ->leftJoin('.groupUsers', 'groupUsers')
- ->addSelect('groupUsers') ;
- }
- return $this;
- }
-
- public function joinProductFamilies()
- {
- if (!$this->isJoinProductFamilies) {
- $this->isJoinProductFamilies = true;
-
- return $this
- ->leftJoin('.productFamilies', 'productFamilies')
- ->addSelect('productFamilies') ;
- }
- return $this;
- }
-
- public function joinProductFamily()
- {
- if (!$this->isJoinProductFamily) {
- $this->isJoinProductFamily = true;
-
- return $this
- ->leftJoin('.productFamily', 'productFamily')
- ->addSelect('productFamily') ;
- }
-
- return $this;
- }
-
- public function joinProductCategories()
- {
- if (!$this->isJoinProductCategories) {
- $this->isJoinProductCategories = true;
-
- return $this
- ->leftJoin('.productCategories', 'productCategories')
- ->addSelect('productCategories') ;
- }
-
- return $this;
- }
-
- public function filterProductFamily(ProductFamilyInterface $productFamily)
- {
- return $this
- ->andWhere('.productFamily = :productFamily')
- ->setParameter(':productFamily', $productFamily);
- }
-
- public function filterConditionDate()
- {
- return $this
- ->andWhere('.permanent = 1 OR ( .dateStart <= :now AND .dateEnd >= :now)')
- ->setParameter(':now', new \DateTime());
- }
-
- public function filterConditionUser(UserInterface $user = null)
- {
- $this->joinUsers();
-
- if ($user) {
- return $this
- ->andWhere(':user MEMBER OF .users OR .users is empty')
- ->setParameter('user', $user);
- } else {
- return $this
- ->andWhere('.users is empty');
- }
- }
-
- public function filterConditionGroupUser(UserInterface $user = null)
- {
- $this->joinGroupUsers();
-
- if ($user) {
- return $this
- ->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
- ->setParameter('groupUser', $user->getGroupUsers());
- } else {
- return $this
- ->andWhere('.groupUsers is empty');
- }
- }
-
- public function filterConditionProductFamilies(array $productFamilies)
- {
- $this->joinProductFamilies();
-
- return $this
- ->andWhere(':productFamilies MEMBER OF .productFamilies OR .productFamilies is empty')
- ->setParameter('productFamilies', $productFamilies);
- }
-
- public function filterConditionProductFamily(ProductFamilyInterface $productFamily)
- {
- $this->joinProductFamily();
-
- return $this
- ->andWhere(':productFamily MEMBER OF .productFamily OR .productFamily is empty')
- ->setParameter('productFamily', $productFamily);
- }
-
- public function filterConditionProductCategories(array $productCategories)
- {
- $this->joinProductCategories();
-
- return $this
- ->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
- ->setParameter('productCategory', $productCategories);
- }
-
-
- }
|