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.

77 lines
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 $isJoinUser = false;
  9. public function __construct(TicketRepository $repository, PaginatorInterface $paginator)
  10. {
  11. parent::__construct($repository, 'ticket', $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 joinUser(): self
  20. {
  21. if (!$this->isJoinUser) {
  22. $this->isJoinUser = true;
  23. return $this
  24. ->leftJoin('.user', 'user');
  25. }
  26. return $this;
  27. }
  28. public function filterByStatus($statusArray): self
  29. {
  30. return $this
  31. ->andWhere('.status IN (:status)')
  32. ->setParameter('status', $statusArray);
  33. }
  34. public function filterByFirstname(string $firstname)
  35. {
  36. $this->joinUser();
  37. return $this
  38. ->andWhere('.visitorFirstname LIKE :firstname OR user.firstname LIKE :firstname')
  39. ->setParameter('firstname', $firstname);
  40. }
  41. public function filterByLastname(string $lastname)
  42. {
  43. $this->joinUser();
  44. return $this
  45. ->andWhere('.visitorLastname LIKE :lastname OR user.lastname LIKE :lastname')
  46. ->setParameter('lastname', $lastname);
  47. }
  48. public function filterByEmail(string $email)
  49. {
  50. $this->joinUser();
  51. return $this
  52. ->andWhere('.visitorEmail LIKE :email OR user.email LIKE :email')
  53. ->setParameter('email', $email);
  54. }
  55. public function selectCount(): self
  56. {
  57. return $this
  58. ->select('count(ticket.id) as count');
  59. }
  60. }