You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
4.7KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Order;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  5. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  6. use Lc\CaracoleBundle\Model\Product\ProductInterface;
  7. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  8. use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
  9. use Lc\SovBundle\Model\User\UserInterface;
  10. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  11. class OrderProductRepositoryQuery extends AbstractRepositoryQuery
  12. {
  13. protected bool $isJoinProduct = false;
  14. protected bool $isJoinSection = false;
  15. protected bool $isJoinProductFamily = false;
  16. protected bool $isJoinOrderShop = false;
  17. protected bool $isJoinOrderStatus = false;
  18. protected bool $isJoinUser = false;
  19. public function __construct(OrderProductRepository $repository, PaginatorInterface $paginator)
  20. {
  21. parent::__construct($repository, 'orderProduct', $paginator);
  22. }
  23. public function filterByOrderShop(OrderShopInterface $orderShop): self
  24. {
  25. return $this
  26. ->andWhere('.orderShop = :orderShop')
  27. ->setParameter('orderShop', $orderShop);
  28. }
  29. public function filterByProduct(ProductInterface $product): self
  30. {
  31. return $this
  32. ->andWhere('.product = :product')
  33. ->setParameter('product', $product);
  34. }
  35. public function filterByUser(UserInterface $user): self
  36. {
  37. $this->joinOrderShop();
  38. return $this
  39. ->andWhere('orderShop.user = :user')
  40. ->setParameter('user', $user);
  41. }
  42. public function filterByEmailUser(string $email): self
  43. {
  44. $this->joinUser();
  45. return $this
  46. ->andWhere('user.email LIKE :email')
  47. ->setParameter('email', $email);
  48. }
  49. public function filterByFirstnameUser(string $firstname): self
  50. {
  51. $this->joinUser();
  52. return $this
  53. ->andWhere('user.firstname LIKE :firstname')
  54. ->setParameter('firstname', $firstname);
  55. }
  56. public function filterByLastnameUser(string $lastname): self
  57. {
  58. $this->joinUser();
  59. return $this
  60. ->andWhere('user.lastname LIKE :lastname')
  61. ->setParameter('lastname', $lastname);
  62. }
  63. public function filterBySection(SectionInterface $section): self
  64. {
  65. $this->joinOrderShop();
  66. return $this->andWhereSection('orderShop', $section);
  67. }
  68. public function filterByOrderStatus(array $status): self
  69. {
  70. $this->joinOrderStatus();
  71. return $this
  72. ->andWhere('orderStatus.alias IN (:alias)')
  73. ->setParameter('alias', $status);
  74. }
  75. public function selectCount(): self
  76. {
  77. return $this
  78. ->select('count(orderProduct.id) as total');
  79. }
  80. public function joinProduct(): self
  81. {
  82. if (!$this->isJoinProduct) {
  83. $this->isJoinProduct = true;
  84. return $this
  85. ->leftJoin('.product', 'product');
  86. }
  87. return $this;
  88. }
  89. public function joinProductFamily(): self
  90. {
  91. $this->joinProduct();
  92. if (!$this->isJoinProductFamily) {
  93. $this->isJoinProductFamily = true;
  94. return $this
  95. ->leftJoin('product.productFamily', 'productFamily');
  96. }
  97. return $this;
  98. }
  99. public function joinOrderShop(): self
  100. {
  101. if (!$this->isJoinOrderShop) {
  102. $this->isJoinOrderShop = true;
  103. return $this
  104. ->leftJoin('.orderShop', 'orderShop');
  105. }
  106. return $this;
  107. }
  108. public function joinUser(): self
  109. {
  110. if (!$this->isJoinOrderShop) {
  111. $this->joinOrderShop();
  112. }
  113. if (!$this->isJoinUser) {
  114. $this->isJoinUser = true;
  115. return $this
  116. ->leftJoin('orderShop.user', 'user');
  117. }
  118. return $this;
  119. }
  120. public function joinSection(): self
  121. {
  122. if (!$this->isJoinSection) {
  123. $this->isJoinSection = true;
  124. return $this
  125. ->leftJoin('orderShop.section', 'section');
  126. }
  127. return $this;
  128. }
  129. public function joinOrderStatus(): self
  130. {
  131. $this->joinOrderShop();
  132. if (!$this->isJoinOrderStatus) {
  133. $this->isJoinOrderStatus = true;
  134. return $this
  135. ->leftJoin('orderShop.orderStatus', 'orderStatus');
  136. }
  137. return $this;
  138. }
  139. public function filterByMerchant(MerchantInterface $merchant)
  140. {
  141. $this->joinOrderShop();
  142. $this->joinSection();
  143. return $this->andWhere('section.merchant = :merchant')
  144. ->setParameter('merchant', $merchant);
  145. }
  146. }