/** * Post Comment for Ticket * @param Command\CommentCommand $command * @return Comment * * @throws ForbiddenException * @throws TicketNotFoundException */ public function postNewCommentForTicket(Command\CommentCommand $command) { $this->isGranted('CREATE', 'Entity:DiamanteDeskBundle:Comment'); \Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput'); /** * @var $ticket \Diamante\DeskBundle\Model\Ticket\Ticket */ $ticket = $this->loadTicketBy($command->ticket); $author = User::fromString($command->author); $comment = $this->commentFactory->create($command->content, $ticket, $author, $command->private); $this->createAttachments($command, $comment); $ticket->updateStatus(new Status($command->ticketStatus)); $ticket->postNewComment($comment); $this->ticketRepository->store($ticket); $this->dispatchWorkflowEvent($this->registry, $this->dispatcher, $comment); return $comment; }
/** * Creates Comment for Ticket * * @param $content * @param $authorId * @param $messageId * @param array $attachments * @return Ticket|null */ public function createCommentForTicket($content, $authorId, $messageId, array $attachments = null) { $reference = $this->messageReferenceRepository->getReferenceByMessageId($messageId); if (is_null($reference)) { $this->logger->error(sprintf('Ticket not found for message: %s', $messageId)); throw new \RuntimeException('Ticket loading failed, ticket not found.'); } $ticket = $reference->getTicket(); $author = User::fromString($authorId); if (empty($content)) { return null; } $comment = $this->commentFactory->create($content, $ticket, $author); if ($attachments) { $this->createAttachments($attachments, $comment); } $ticket->postNewComment($comment); $this->ticketRepository->store($ticket); $this->dispatchEvents($ticket); return $ticket; }