entityManager = $entityManager; $this->mailMailjetNotification = $mailMailjetNotification; $this->ticketMessageFactory = $ticketMessageFactory; $this->eventDispatcher = $eventDispatcher; } public function create(array $params = []): TicketMessageInterface { $ticket = $params['ticket']; $ticketMessage = $this->ticketMessageFactory->create($ticket); $ticketMessage->setStatus(1); $ticketMessage->setTicket($ticket); $ticketMessage->setMessage($params['message']); if (isset($params['answerByAdmin']) && $params['answerByAdmin']) { $ticketMessage->setAnswerByAdmin($params['answerByAdmin']); } $this->entityManager->persist($ticketMessage); if (isset($params['imageFilename']) && $params['imageFilename']) { $ticketMessage->setImageFilename($params['imageFilename']); } if (isset($params['closeTicket']) && $params['closeTicket']) { $ticket->setStatus(TicketModel::TICKET_STATUS_CLOSED); } $ticket->setUpdatedAt(new \DateTime()); $this->entityManager->create($ticket); $this->entityManager->flush(); $this->eventDispatcher->dispatch(new TicketEvent($ticket), TicketEvent::NEW_MESSAGE_EVENT); return $ticketMessage; } }