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.

59 line
1.6KB

  1. <?php
  2. namespace domain\Ticket\Ticket;
  3. use domain\User\User\User;
  4. use domain\_\AbstractRepository;
  5. class TicketRepository extends AbstractRepository
  6. {
  7. protected TicketRepositoryQuery $query;
  8. protected TicketSolver $ticketSolver;
  9. public function loadDependencies(): void
  10. {
  11. $this->loadQuery(TicketRepositoryQuery::class);
  12. $this->ticketSolver = $this->loadService(TicketSolver::class);
  13. }
  14. public function getDefaultOptionsSearch(): array
  15. {
  16. return [
  17. self::WITH => ['user', 'producer', 'ticketMessages', 'ticketUsers'],
  18. self::JOIN_WITH => [],
  19. self::ORDER_BY => '',
  20. self::ATTRIBUTE_ID_PRODUCER => 'ticket.id_producer'
  21. ];
  22. }
  23. public function findOneTicketById(int $id): ?Ticket
  24. {
  25. return $this->createQuery()
  26. ->filterById($id)
  27. ->findOne();
  28. }
  29. public function countTicketsUnreadByUser(User $user): int
  30. {
  31. $ticketsArray = $this->createDefaultQuery()->find();
  32. return $this->ticketSolver->countTicketsUnreadByUserFromArray($ticketsArray, $user);
  33. }
  34. public function countTicketsAdminUnreadByUser(User $user): int
  35. {
  36. $ticketsArray = $this->createQuery()->find();
  37. return $this->ticketSolver->countTicketsUnreadByUserFromArray($ticketsArray, $user);
  38. }
  39. public function findTicketsAdminStatusOpen()
  40. {
  41. return $this->createQuery()
  42. ->filterByStatusOpen()
  43. ->find();
  44. }
  45. public function countTicketsAdminStatusOpen()
  46. {
  47. return count($this->findTicketsAdminStatusOpen());
  48. }
  49. }