|
- <?php
-
- namespace Lc\SovBundle\Repository\Ticket;
-
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Repository\AbstractRepositoryQuery;
-
- class TicketRepositoryQuery extends AbstractRepositoryQuery implements TicketRepositoryQueryInterface
- {
- protected bool $isJoinUser = false;
-
- public function __construct(TicketRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'r', $paginator);
- }
-
- public function filterByUser(UserInterface $user): self
- {
- return $this
- ->andWhere('.user = :user')
- ->setParameter('user', $user);
- }
-
- public function filterByStatus($statusArray): self
- {
- return $this
- ->andWhere('.status IN (:status)')
- ->setParameter('status', $statusArray);
- }
-
- public function filterByFirstname(string $firstname)
- {
- $this->joinUser();
-
- return $this
- ->andWhere('.visitorFirstname LIKE :firstname OR u.firstname LIKE :firstname')
- ->setParameter('firstname', '%'.$firstname.'%');
- }
-
- public function filterByLastname(string $lastname)
- {
- $this->joinUser();
-
- return $this
- ->andWhere('.visitorLastname LIKE :lastname OR u.lastname LIKE :lastname')
- ->setParameter('lastname', '%'.$lastname.'%');
- }
-
- public function filterByEmail(string $email)
- {
- $this->joinUser();
-
- return $this
- ->andWhere('.visitorEmail LIKE :email OR u.email LIKE :email')
- ->setParameter('email', '%'.$email.'%');
- }
-
- public function selectCount(): self
- {
- return $this
- ->select('count(r.id) as count');
- }
-
- public function joinUser(): self
- {
- if (!$this->isJoinUser) {
- $this->isJoinUser = true;
-
- return $this->leftJoin('.user', 'u');
- }
- return $this;
- }
- }
|