Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

TicketUserBuilder.php 1.2KB

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