|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Order;
-
- use App\Entity\Delivery\DeliveryAvailabilityPointSale;
- use App\Entity\Delivery\DeliveryAvailabilityZone;
- use App\Entity\PointSale\PointSale;
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\CaracoleBundle\Model\Address\AddressInterface;
- use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
- use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
- use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
- use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
- use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
- use Lc\CaracoleBundle\Model\User\VisitorInterface;
- use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Repository\AbstractRepositoryQuery;
- use DateTime;
-
- class OrderShopRepositoryQuery extends AbstractRepositoryQuery
- {
- use SectionRepositoryQueryTrait;
-
- protected bool $isJoinProduct = false;
- protected bool $isJoinOrderProduct = false;
- protected bool $isJoinOrderReductionCredits = false;
- protected bool $isJoinOrderReductionCarts = false;
- protected bool $isJoinOrderStatus = false;
- protected bool $isJoinMerchant = false;
- protected bool $isJoinSection = false;
- protected bool $isJoinComplementaryOrderShops = false;
- protected bool $isJoinDeliveryPointSale = false;
-
- public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'r', $paginator);
- }
-
- // @TODO : nécessaire ?
- public function selectParam($select): self
- {
- return $this
- ->addSelect($select);
- }
-
- public function selectCount(): self
- {
- return $this
- ->select('count(r.id) as total');
- }
-
- public function filterByMerchant(MerchantInterface $merchant)
- {
- $this->joinMerchant();
- return $this->andWhere('s.merchant = :merchant')
- ->setParameter('merchant', $merchant);
- }
-
- public function filterByUser(UserInterface $user): self
- {
- return $this
- ->andWhere('.user = :user')
- ->setParameter('user', $user);
- }
-
- public function filterIsMerchantOnline(): self
- {
- $this->joinMerchant();
- return $this
- ->andWhere('merchant.status = :status')
- ->setParameter(':status', 1);
- }
-
- public function filterByDateStart(string $dateField, DateTime $dateStart): self
- {
- return $this
- ->andWhere('.' . $dateField . ' >= :dateStart')
- ->setParameter('dateStart', $dateStart);
- }
-
- public function filterByDateEnd(string $dateField, DateTime $dateEnd): self
- {
- return $this
- ->andWhere('.' . $dateField . ' <= :dateEnd')
- ->setParameter('dateEnd', $dateEnd);
- }
-
- public function filterByVisitor(VisitorInterface $visitor): self
- {
- return $this
- ->andWhere('.visitor = :visitor')
- ->setParameter('visitor', $visitor);
- }
-
- public function filterByAddress(AddressInterface $address): self
- {
- return $this
- ->andWhere('.deliveryAddress = :address OR .invoiceAddress = :address')
- ->setParameter('address', $address);
- }
-
- public function filterByStatus(array $statusArray): self
- {
- $this->joinOrderStatus();
-
- return $this
- ->andWhere('os.alias IN (:alias)')
- ->setParameter('alias', $statusArray);
- }
-
- public function filterByReductionCredit(ReductionCreditInterface $reductionCredit): self
- {
- $this->joinOrderReductionCredits();
-
- return $this
- ->andWhere('orc.reductionCredit = :reductionCredit')
- ->setParameter('reductionCredit', $reductionCredit);
- }
-
- public function filterByReductionCart(ReductionCartInterface $reductionCart): self
- {
- $this->joinOrderReductionCarts();
-
- return $this
- ->andWhere('orcart.reductionCart = :reductionCart')
- ->setParameter('reductionCart', $reductionCart);
- }
-
- public function filterByCycleNumber(int $cycleNumber): self
- {
- return $this
- ->andWhere('.cycleNumber = :cycleNumber')
- ->setParameter('cycleNumber', $cycleNumber);
- }
-
- public function filterIsNotComplementaryOrderShop(): self
- {
- return $this
- ->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
- }
-
- public function filterIsNullMainOrderShop(): self
- {
- return $this
- ->andWhere('.mainOrderShop IS NULL');
- }
-
- public function selectOrderReductionCarts(): self
- {
- $this->joinOrderReductionCarts();
-
- return $this->addSelect('orcart');
- }
-
- public function joinOrderProduct(): self
- {
- if (!$this->isJoinOrderProduct) {
- $this->isJoinOrderProduct = true;
-
- return $this
- ->innerJoin('.orderProducts', 'op');
- }
- return $this;
- }
-
- public function joinOrderReductionCredits(): self
- {
- if (!$this->isJoinOrderReductionCredits) {
- $this->isJoinOrderReductionCredits = true;
-
- return $this
- ->innerJoin('.orderReductionCredits', 'orc');
- }
- return $this;
- }
-
- public function joinOrderStatus(): self
- {
- if (!$this->isJoinOrderStatus) {
- $this->isJoinOrderStatus = true;
-
- return $this
- ->leftJoin('.orderStatus', 'os');
- }
- return $this;
- }
-
- public function joinOrderReductionCarts(): self
- {
- if (!$this->isJoinOrderReductionCarts) {
- $this->isJoinOrderReductionCarts = true;
-
- return $this
- ->leftJoin('.orderReductionCarts', 'orcart');
- }
- return $this;
- }
-
- public function joinMerchant(): self
- {
- $this->joinSection();
- if (!$this->isJoinMerchant) {
- $this->isJoinMerchant = true;
-
- return $this
- ->leftJoin('s.merchant', 'merchant');
- }
- return $this;
- }
-
- public function joinSection(): self
- {
- if (!$this->isJoinSection) {
- $this->isJoinSection = true;
-
- return $this
- ->leftJoin('.section', 's');
- }
- return $this;
- }
-
- public function joinComplementaryOrderShops(): self
- {
- if (!$this->isJoinComplementaryOrderShops) {
- $this->isJoinComplementaryOrderShops = true;
-
- return $this
- ->leftJoin('.complementaryOrderShops', 'complementaryOrderShops');
- }
- return $this;
- }
-
- public function joinDeliveryPointSale(): self
- {
- if (!$this->isJoinDeliveryPointSale) {
- $this->isJoinDeliveryPointSale = true;
-
- return $this
- ->leftJoin('.deliveryPointSale', 'pointSale');
- }
- return $this;
- }
-
- }
|