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.

PointSaleRepositoryQuery.php 1.8KB

3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\PointSale;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  5. use Lc\SovBundle\Model\User\UserInterface;
  6. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  7. class PointSaleRepositoryQuery extends AbstractRepositoryQuery
  8. {
  9. protected $isJoinUserPointSales = false;
  10. public function __construct(PointSaleRepository $repository, PaginatorInterface $paginator)
  11. {
  12. parent::__construct($repository, 'pointSale', $paginator);
  13. }
  14. public function filterByUser(UserInterface $user): self
  15. {
  16. $this->joinUserPointSales();
  17. return $this
  18. ->andWhere('userPointSales.user = :user')
  19. ->setParameter('user', $user);
  20. }
  21. public function filterByMerchant(MerchantInterface $merchant)
  22. {
  23. return $this
  24. ->andWhere(':merchant MEMBER OF .merchants')
  25. ->setParameter(':merchant', $merchant);
  26. }
  27. public function filterIsNotPublic(): self
  28. {
  29. return $this->andWhere('.isPublic = 0');
  30. }
  31. public function filterIsPublic(): self
  32. {
  33. return $this->andWhere('.isPublic = 1');
  34. }
  35. public function filterByIsPublic(int $isPublic): self
  36. {
  37. return $this->andWhere('.isPublic = ' . $isPublic);
  38. }
  39. public function filterLikeCode(string $code): self
  40. {
  41. return $this
  42. ->andWhere('.code LIKE :code')
  43. ->setParameter('code', $code);
  44. }
  45. public function joinUserPointSales(): self
  46. {
  47. if (!$this->isJoinUserPointSales) {
  48. $this->isJoinUserPointSales = true;
  49. return $this
  50. ->innerJoin('.userPointSales', 'userPointSales');
  51. }
  52. return $this;
  53. }
  54. }