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.

77 satır
2.1KB

  1. <?php
  2. namespace domain\Ticket\Ticket;
  3. use domain\Producer\Producer\Producer;
  4. use domain\Ticket\TicketMessage\TicketMessage;
  5. use domain\Ticket\TicketMessage\TicketMessageBuilder;
  6. use domain\Ticket\TicketUser\TicketUserBuilder;
  7. use domain\User\User\User;
  8. use domain\_\AbstractBuilder;
  9. class TicketBuilder extends AbstractBuilder
  10. {
  11. protected TicketMessageBuilder $ticketMessageBuilder;
  12. protected TicketUserBuilder $ticketUserBuilder;
  13. public function loadDependencies(): void
  14. {
  15. $this->ticketMessageBuilder = $this->loadService(TicketMessageBuilder::class);
  16. $this->ticketUserBuilder = $this->loadService(TicketUserBuilder::class);
  17. }
  18. public function instanciateTicket(Producer $producer, User $user): Ticket
  19. {
  20. $ticket = new Ticket();
  21. $ticket->status = Ticket::STATUS_OPEN;
  22. $ticket->populateProducer($producer);
  23. $ticket->populateUser($user);
  24. return $ticket;
  25. }
  26. public function createTicket(Producer $producer, User $user): Ticket
  27. {
  28. $ticket = $this->instanciateTicket($producer, $user);
  29. $this->create($ticket);
  30. return $ticket;
  31. }
  32. public function updateTicketStatus(Ticket $ticket, string $status)
  33. {
  34. $ticket->status = $status;
  35. $this->update($ticket);
  36. $this->updateTicketUpdatedAt($ticket);
  37. }
  38. public function closeTicket(Ticket $ticket)
  39. {
  40. $this->updateTicketStatus($ticket, Ticket::STATUS_CLOSED);
  41. }
  42. public function openTicket(Ticket $ticket)
  43. {
  44. $this->updateTicketStatus($ticket, Ticket::STATUS_OPEN);
  45. }
  46. public function updateTicketUpdatedAt(Ticket $ticket)
  47. {
  48. $ticket->updated_at = date('Y-m-d H:i:s');
  49. $this->update($ticket);
  50. }
  51. public function createTicketMessage(TicketMessage $ticketMessage)
  52. {
  53. $this->updateTicketUpdatedAt($ticketMessage->ticket);
  54. return $this->create($ticketMessage);
  55. }
  56. public function viewTicket(Ticket $ticket, User $user)
  57. {
  58. $ticketUser = $this->ticketUserBuilder->createTicketUserIfNotExist($ticket, $user);
  59. $this->ticketUserBuilder->updateTicketUserReadAt($ticketUser);
  60. }
  61. }