Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TicketUserBuilder.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. }