Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

TicketMessageBuilder.php 2.9KB

3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Lc\SovBundle\Builder\Ticket;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\SovBundle\Notification\MailMailjetNotification;
  5. use Lc\SovBundle\Component\FormComponent;
  6. use Lc\SovBundle\Factory\Ticket\TicketFactory;
  7. use Lc\SovBundle\Factory\Ticket\TicketMessageFactory;
  8. use Lc\SovBundle\Model\Ticket\TicketInterface;
  9. use Lc\SovBundle\Model\Ticket\TicketMessageInterface;
  10. use Lc\SovBundle\Model\Ticket\TicketModel;
  11. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  12. class TicketMessageBuilder
  13. {
  14. protected EntityManagerInterface $entityManager;
  15. protected MailMailjetNotification $mailMailjetNotification;
  16. protected TicketMessageFactory $ticketMessageFactory;
  17. public function __construct(
  18. EntityManagerInterface $entityManager,
  19. MailMailjetNotification $mailMailjetNotification,
  20. TicketMessageFactory $ticketMessageFactory
  21. ) {
  22. $this->entityManager = $entityManager;
  23. $this->mailMailjetNotification = $mailMailjetNotification;
  24. $this->ticketMessageFactory = $ticketMessageFactory;
  25. }
  26. public function create(array $params = []): TicketMessageInterface
  27. {
  28. $ticket = $params['ticket'];
  29. $ticketMessage = $this->ticketMessageFactory->create($ticket);
  30. $ticketMessage->setStatus(1);
  31. $ticketMessage->setTicket($ticket);
  32. $ticketMessage->setMessage($params['message']);
  33. if (isset($params['answerByAdmin']) && $params['answerByAdmin']) {
  34. $ticketMessage->setAnswerByAdmin($params['answerByAdmin']);
  35. // envoi email au client
  36. $this->mailMailjetNotification->send(
  37. [
  38. MailMailjetNotification::SUBJECT => 'Réponse à votre demande',
  39. MailMailjetNotification::TO_EMAIL => $ticket->getUser() ? $ticket->getUser()->getEmail(
  40. ) : $ticket->getVisitorEmail(),
  41. MailMailjetNotification::CONTENT_TEMPLATE => 'mail/ticket-response',
  42. MailMailjetNotification::CONTENT_DATA => [
  43. 'firstname' => $ticket->getUser() ? $ticket->getUser()->getFirstname(
  44. ) : $ticket->getVisitorFirstname(),
  45. 'ticket' => $ticket,
  46. ],
  47. ]
  48. );
  49. }
  50. $this->entityManager->persist($ticketMessage);
  51. if (isset($params['imageFilename']) && $params['imageFilename']) {
  52. $ticketMessage->setImageFilename($params['imageFilename']);
  53. }
  54. if (isset($params['closeTicket']) && $params['closeTicket']) {
  55. $ticket->setStatus(TicketModel::TICKET_STATUS_CLOSED);
  56. }
  57. $ticket->setUpdatedAt(new \DateTime());
  58. $this->entityManager->persist($ticket);
  59. $this->entityManager->flush();
  60. return $ticketMessage;
  61. }
  62. }