Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

68 lines
2.4KB

  1. <?php
  2. namespace Lc\SovBundle\Builder\Ticket;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\SovBundle\Event\Ticket\TicketEvent;
  5. use Lc\SovBundle\Notification\MailMailjetNotification;
  6. use Lc\SovBundle\Component\FormComponent;
  7. use Lc\SovBundle\Factory\Ticket\TicketFactory;
  8. use Lc\SovBundle\Factory\Ticket\TicketMessageFactory;
  9. use Lc\SovBundle\Model\Ticket\TicketInterface;
  10. use Lc\SovBundle\Model\Ticket\TicketMessageInterface;
  11. use Lc\SovBundle\Model\Ticket\TicketModel;
  12. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. class TicketMessageBuilder
  15. {
  16. protected EntityManagerInterface $entityManager;
  17. protected MailMailjetNotification $mailMailjetNotification;
  18. protected TicketMessageFactory $ticketMessageFactory;
  19. protected EventDispatcherInterface $eventDispatcher;
  20. public function __construct(
  21. EntityManagerInterface $entityManager,
  22. MailMailjetNotification $mailMailjetNotification,
  23. TicketMessageFactory $ticketMessageFactory,
  24. EventDispatcherInterface $eventDispatcher
  25. ) {
  26. $this->entityManager = $entityManager;
  27. $this->mailMailjetNotification = $mailMailjetNotification;
  28. $this->ticketMessageFactory = $ticketMessageFactory;
  29. $this->eventDispatcher = $eventDispatcher;
  30. }
  31. public function create(array $params = []): TicketMessageInterface
  32. {
  33. $ticket = $params['ticket'];
  34. $ticketMessage = $this->ticketMessageFactory->create($ticket);
  35. $ticketMessage->setStatus(1);
  36. $ticketMessage->setTicket($ticket);
  37. $ticketMessage->setMessage($params['message']);
  38. if (isset($params['answerByAdmin']) && $params['answerByAdmin']) {
  39. $ticketMessage->setAnswerByAdmin($params['answerByAdmin']);
  40. }
  41. $this->entityManager->persist($ticketMessage);
  42. if (isset($params['imageFilename']) && $params['imageFilename']) {
  43. $ticketMessage->setImageFilename($params['imageFilename']);
  44. }
  45. if (isset($params['closeTicket']) && $params['closeTicket']) {
  46. $ticket->setStatus(TicketModel::TICKET_STATUS_CLOSED);
  47. }
  48. $ticket->setUpdatedAt(new \DateTime());
  49. $this->entityManager->create($ticket);
  50. $this->entityManager->flush();
  51. $this->eventDispatcher->dispatch(new TicketEvent($ticket), TicketEvent::NEW_MESSAGE_EVENT);
  52. return $ticketMessage;
  53. }
  54. }