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.

75 line
2.0KB

  1. <?php
  2. namespace Lc\SovBundle\Repository\Ticket;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\SovBundle\Model\User\UserInterface;
  5. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  6. class TicketRepositoryQuery extends AbstractRepositoryQuery implements TicketRepositoryQueryInterface
  7. {
  8. protected bool $isJoinUser = false;
  9. public function __construct(TicketRepository $repository, PaginatorInterface $paginator)
  10. {
  11. parent::__construct($repository, 'r', $paginator);
  12. }
  13. public function filterByUser(UserInterface $user): self
  14. {
  15. return $this
  16. ->andWhere('.user = :user')
  17. ->setParameter('user', $user);
  18. }
  19. public function filterByStatus($statusArray): self
  20. {
  21. return $this
  22. ->andWhere('.status IN (:status)')
  23. ->setParameter('status', $statusArray);
  24. }
  25. public function filterByFirstname(string $firstname)
  26. {
  27. $this->joinUser();
  28. return $this
  29. ->andWhere('.visitorFirstname LIKE :firstname OR u.firstname LIKE :firstname')
  30. ->setParameter('firstname', '%'.$firstname.'%');
  31. }
  32. public function filterByLastname(string $lastname)
  33. {
  34. $this->joinUser();
  35. return $this
  36. ->andWhere('.visitorLastname LIKE :lastname OR u.lastname LIKE :lastname')
  37. ->setParameter('lastname', '%'.$lastname.'%');
  38. }
  39. public function filterByEmail(string $email)
  40. {
  41. $this->joinUser();
  42. return $this
  43. ->andWhere('.visitorEmail LIKE :email OR u.email LIKE :email')
  44. ->setParameter('email', '%'.$email.'%');
  45. }
  46. public function selectCount(): self
  47. {
  48. return $this
  49. ->select('count(r.id) as count');
  50. }
  51. public function joinUser(): self
  52. {
  53. if (!$this->isJoinUser) {
  54. $this->isJoinUser = true;
  55. return $this->leftJoin('.user', 'u');
  56. }
  57. return $this;
  58. }
  59. }