|
- <?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, 'orderProduct', $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('orderStatus.alias IN (:alias)')
- ->setParameter('alias', $status);
- }
-
-
- public function selectCount(): self
- {
- return $this
- ->select('count(orderProduct.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', 'orderStatus');
- }
- return $this;
- }
- }
|