選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

76 行
2.9KB

  1. <?php
  2. namespace Lc\SovBundle\Builder\Ticket;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\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. }