|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Order;
-
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Model\Product\ProductInterface;
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
- use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Repository\AbstractRepositoryQuery;
-
- class OrderProductRepositoryQuery extends AbstractRepositoryQuery
- {
-
- protected bool $isJoinProduct = false;
- protected bool $isJoinProductFamily = false;
- protected bool $isJoinOrderShop = false;
- protected bool $isJoinOrderStatus = false;
-
- public function __construct(OrderProductRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'r', $paginator);
- }
-
- public function filterByOrderShop(OrderShopInterface $orderShop): self
- {
- return $this
- ->andWhere('.orderShop = :orderShop')
- ->setParameter('orderShop', $orderShop);
- }
-
- public function filterByProduct(ProductInterface $product): self
- {
- return $this
- ->andWhere('.product = :product')
- ->setParameter('product', $product);
- }
-
- public function filterByUser(UserInterface $user): self
- {
- $this->joinOrderShop();
-
- return $this
- ->andWhere('orderShop.user = :user')
- ->setParameter('user', $user);
- }
-
- public function filterBySection(SectionInterface $section): self
- {
- $this->joinOrderShop();
-
- return $this->andWhereSection('orderShop', $section);
- }
-
- public function filterByOrderStatus(array $status): self
- {
- $this->joinOrderStatus();
-
- return $this
- ->andWhere('os.alias IN (:alias)')
- ->setParameter('alias', $status);
- }
-
-
- public function selectCount(): self
- {
- return $this
- ->select('count(r.id) as total');
- }
-
- public function joinProduct(): self
- {
- if (!$this->isJoinProduct) {
- $this->isJoinProduct = true;
-
- return $this
- ->leftJoin('.product', 'product');
- }
- return $this;
- }
-
- public function joinProductFamily(): self
- {
- $this->joinProduct();
- if (!$this->isJoinProductFamily) {
- $this->isJoinProductFamily = true;
-
- return $this
- ->leftJoin('product.productFamily', 'productFamily');
- }
- return $this;
- }
-
- public function joinOrderShop(): self
- {
- if (!$this->isJoinOrderShop) {
- $this->isJoinOrderShop = true;
-
- return $this
- ->leftJoin('.orderShop', 'orderShop');
- }
- return $this;
- }
-
- public function joinOrderStatus(): self
- {
- $this->joinOrderShop();
- if (!$this->isJoinOrderStatus) {
- $this->isJoinOrderStatus = true;
-
- return $this
- ->leftJoin('orderShop.orderStatus', 'os');
- }
- return $this;
- }
- }
|