|
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Order;
-
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
- 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 $isJoinSection = false;
- protected bool $isJoinProductFamily = false;
- protected bool $isJoinOrderShop = false;
- protected bool $isJoinOrderStatus = false;
- protected bool $isJoinUser = 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 filterByEmailUser(string $email): self
- {
- $this->joinUser();
-
- return $this
- ->andWhere('user.email LIKE :email')
- ->setParameter('email', $email);
- }
-
- public function filterByFirstnameUser(string $firstname): self
- {
- $this->joinUser();
-
- return $this
- ->andWhere('user.firstname LIKE :firstname')
- ->setParameter('firstname', $firstname);
- }
-
- public function filterByLastnameUser(string $lastname): self
- {
- $this->joinUser();
-
- return $this
- ->andWhere('user.lastname LIKE :lastname')
- ->setParameter('lastname', $lastname);
- }
-
- 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 joinUser(): self
- {
- if (!$this->isJoinOrderShop) {
- $this->joinOrderShop();
- }
-
- if (!$this->isJoinUser) {
- $this->isJoinUser = true;
-
- return $this
- ->leftJoin('orderShop.user', 'user');
- }
- return $this;
- }
-
- public function joinSection(): self
- {
- if (!$this->isJoinSection) {
- $this->isJoinSection = true;
-
- return $this
- ->leftJoin('orderShop.section', 'section');
- }
- return $this;
- }
-
- public function joinOrderStatus(): self
- {
- $this->joinOrderShop();
- if (!$this->isJoinOrderStatus) {
- $this->isJoinOrderStatus = true;
-
- return $this
- ->leftJoin('orderShop.orderStatus', 'orderStatus');
- }
- return $this;
- }
-
- public function filterByMerchant(MerchantInterface $merchant)
- {
- $this->joinOrderShop();
- $this->joinSection();
- return $this->andWhere('section.merchant = :merchant')
- ->setParameter('merchant', $merchant);
- }
- }
|