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.

118 lines
3.1KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Order;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  5. use Lc\CaracoleBundle\Model\Product\ProductInterface;
  6. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  7. use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
  8. use Lc\SovBundle\Model\User\UserInterface;
  9. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  10. class OrderProductRepositoryQuery extends AbstractRepositoryQuery
  11. {
  12. protected bool $isJoinProduct = false;
  13. protected bool $isJoinProductFamily = false;
  14. protected bool $isJoinOrderShop = false;
  15. protected bool $isJoinOrderStatus = false;
  16. public function __construct(OrderProductRepository $repository, PaginatorInterface $paginator)
  17. {
  18. parent::__construct($repository, 'r', $paginator);
  19. }
  20. public function filterByOrderShop(OrderShopInterface $orderShop): self
  21. {
  22. return $this
  23. ->andWhere('.orderShop = :orderShop')
  24. ->setParameter('orderShop', $orderShop);
  25. }
  26. public function filterByProduct(ProductInterface $product): self
  27. {
  28. return $this
  29. ->andWhere('.product = :product')
  30. ->setParameter('product', $product);
  31. }
  32. public function filterByUser(UserInterface $user): self
  33. {
  34. $this->joinOrderShop();
  35. return $this
  36. ->andWhere('orderShop.user = :user')
  37. ->setParameter('user', $user);
  38. }
  39. public function filterBySection(SectionInterface $section): self
  40. {
  41. $this->joinOrderShop();
  42. return $this->andWhereSection('orderShop', $section);
  43. }
  44. public function filterByOrderStatus(array $status): self
  45. {
  46. $this->joinOrderStatus();
  47. return $this
  48. ->andWhere('os.alias IN (:alias)')
  49. ->setParameter('alias', $status);
  50. }
  51. public function selectCount(): self
  52. {
  53. return $this
  54. ->select('count(r.id) as total');
  55. }
  56. public function joinProduct(): self
  57. {
  58. if (!$this->isJoinProduct) {
  59. $this->isJoinProduct = true;
  60. return $this
  61. ->leftJoin('.product', 'product');
  62. }
  63. return $this;
  64. }
  65. public function joinProductFamily(): self
  66. {
  67. $this->joinProduct();
  68. if (!$this->isJoinProductFamily) {
  69. $this->isJoinProductFamily = true;
  70. return $this
  71. ->leftJoin('product.productFamily', 'productFamily');
  72. }
  73. return $this;
  74. }
  75. public function joinOrderShop(): self
  76. {
  77. if (!$this->isJoinOrderShop) {
  78. $this->isJoinOrderShop = true;
  79. return $this
  80. ->leftJoin('.orderShop', 'orderShop');
  81. }
  82. return $this;
  83. }
  84. public function joinOrderStatus(): self
  85. {
  86. $this->joinOrderShop();
  87. if (!$this->isJoinOrderStatus) {
  88. $this->isJoinOrderStatus = true;
  89. return $this
  90. ->leftJoin('orderShop.orderStatus', 'os');
  91. }
  92. return $this;
  93. }
  94. }