Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

72 lines
1.9KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\User;
  3. use App\Entity\Merchant\Merchant;
  4. use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
  5. use Lc\SovBundle\Repository\User\UserRepositoryQuery as SovUserRepositoryQuery;
  6. class UserRepositoryQuery extends SovUserRepositoryQuery
  7. {
  8. use MerchantRepositoryQueryTrait;
  9. protected $isJoinUserMerchants = false;
  10. protected $isJoinAddresses = false;
  11. public function joinUserMerchants(): self
  12. {
  13. if (!$this->isJoinUserMerchants) {
  14. $this->isJoinUserMerchants = true;
  15. return $this
  16. ->innerJoin('.userMerchants', 'userMerchants');
  17. }
  18. return $this;
  19. }
  20. public function joinAddresses(): self
  21. {
  22. if (!$this->isJoinAddresses) {
  23. $this->isJoinAddresses = true;
  24. return $this
  25. ->innerJoin('.addresses', 'addresses');
  26. }
  27. return $this;
  28. }
  29. public function filterMerchantIsActive(): self
  30. {
  31. $this->joinUserMerchants();
  32. return $this
  33. ->andWhere('userMerchants.active = 1');
  34. }
  35. public function filterByMerchant(Merchant $merchant): self
  36. {
  37. $this->joinUserMerchants();
  38. return $this
  39. ->andWhere('userMerchants.merchant = :merchant')
  40. ->setParameter('merchant', $merchant);
  41. }
  42. public function filterByExtraInfoZip(string $zip)
  43. {
  44. $this->joinAddresses();
  45. return $this
  46. ->andWhere('.extraInfoZip LIKE :extraInfoZip OR addresses.zip LIKE :extraInfoZip')
  47. ->setParameter('extraInfoZip', $zip);
  48. }
  49. public function filterByExtraInfoCity(string $city)
  50. {
  51. $this->joinAddresses();
  52. return $this
  53. ->andWhere('.extraInfoCity LIKE :extraInfoCity OR addresses.city LIKE :extraInfoCity')
  54. ->setParameter('extraInfoCity', $city);
  55. }
  56. }