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.

49 lines
1.4KB

  1. <?php
  2. namespace common\logic\Ticket\TicketUser\Service;
  3. use common\logic\AbstractBuilder;
  4. use common\logic\Ticket\Ticket\Model\Ticket;
  5. use common\logic\Ticket\TicketUser\Model\TicketUser;
  6. use common\logic\Ticket\TicketUser\Repository\TicketUserRepository;
  7. use common\logic\User\User\Model\User;
  8. class TicketUserBuilder extends AbstractBuilder
  9. {
  10. protected TicketUserRepository $ticketUserRepository;
  11. public function loadDependencies(): void
  12. {
  13. $this->ticketUserRepository = $this->loadService(TicketUserRepository::class);
  14. }
  15. public function instanciateTicketUser(Ticket $ticket, User $user): TicketUser
  16. {
  17. $ticketUser = new TicketUser();
  18. $ticketUser->populateTicket($ticket);
  19. $ticketUser->populateUser($user);
  20. return $ticketUser;
  21. }
  22. public function createTicketUser(Ticket $ticket, User $user): TicketUser
  23. {
  24. $ticketUser = $this->instanciateTicketUser($ticket, $user);
  25. $this->saveCreate($ticketUser);
  26. return $ticketUser;
  27. }
  28. public function createTicketUserIfNotExist(Ticket $ticket, User $user): TicketUser
  29. {
  30. return $this->ticketUserRepository->findOneTicketUser($ticket, $user)
  31. ?? $this->createTicketUser($ticket, $user);
  32. }
  33. public function updateTicketUserReadAt(TicketUser $ticketUser)
  34. {
  35. $ticketUser->read_at = date('Y-m-d H:i:s');
  36. $this->saveUpdate($ticketUser);
  37. }
  38. }