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.

138 lines
3.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. public function __construct(OrderProductRepository $repository, PaginatorInterface $paginator)
  19. {
  20. parent::__construct($repository, 'orderProduct', $paginator);
  21. }
  22. public function filterByOrderShop(OrderShopInterface $orderShop): self
  23. {
  24. return $this
  25. ->andWhere('.orderShop = :orderShop')
  26. ->setParameter('orderShop', $orderShop);
  27. }
  28. public function filterByProduct(ProductInterface $product): self
  29. {
  30. return $this
  31. ->andWhere('.product = :product')
  32. ->setParameter('product', $product);
  33. }
  34. public function filterByUser(UserInterface $user): self
  35. {
  36. $this->joinOrderShop();
  37. return $this
  38. ->andWhere('orderShop.user = :user')
  39. ->setParameter('user', $user);
  40. }
  41. public function filterBySection(SectionInterface $section): self
  42. {
  43. $this->joinOrderShop();
  44. return $this->andWhereSection('orderShop', $section);
  45. }
  46. public function filterByOrderStatus(array $status): self
  47. {
  48. $this->joinOrderStatus();
  49. return $this
  50. ->andWhere('orderStatus.alias IN (:alias)')
  51. ->setParameter('alias', $status);
  52. }
  53. public function selectCount(): self
  54. {
  55. return $this
  56. ->select('count(orderProduct.id) as total');
  57. }
  58. public function joinProduct(): self
  59. {
  60. if (!$this->isJoinProduct) {
  61. $this->isJoinProduct = true;
  62. return $this
  63. ->leftJoin('.product', 'product');
  64. }
  65. return $this;
  66. }
  67. public function joinProductFamily(): self
  68. {
  69. $this->joinProduct();
  70. if (!$this->isJoinProductFamily) {
  71. $this->isJoinProductFamily = true;
  72. return $this
  73. ->leftJoin('product.productFamily', 'productFamily');
  74. }
  75. return $this;
  76. }
  77. public function joinOrderShop(): self
  78. {
  79. if (!$this->isJoinOrderShop) {
  80. $this->isJoinOrderShop = true;
  81. return $this
  82. ->leftJoin('.orderShop', 'orderShop');
  83. }
  84. return $this;
  85. }
  86. public function joinSection(): self
  87. {
  88. if (!$this->isJoinSection) {
  89. $this->isJoinSection = true;
  90. return $this
  91. ->leftJoin('orderShop.section', 'section');
  92. }
  93. return $this;
  94. }
  95. public function joinOrderStatus(): self
  96. {
  97. $this->joinOrderShop();
  98. if (!$this->isJoinOrderStatus) {
  99. $this->isJoinOrderStatus = true;
  100. return $this
  101. ->leftJoin('orderShop.orderStatus', 'orderStatus');
  102. }
  103. return $this;
  104. }
  105. public function filterByMerchant(MerchantInterface $merchant){
  106. $this->joinOrderShop();
  107. $this->joinSection();
  108. return $this->andWhere('section.merchant = :merchant')
  109. ->setParameter('merchant', $merchant);
  110. }
  111. }