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.

OrderProductRepositoryQuery.php 4.7KB

3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. }