/** * Create new attachment and assign it to the attachment holder * @param string $filename * @param string $content * @param AttachmentHolder $holder * @return \Diamante\DeskBundle\Model\Attachment\Attachment */ public function createNewAttachment($filename, $content, AttachmentHolder $holder) { $this->validateFilename($filename); $this->validateContent($content); $filenamePrefix = $this->exposeFilenamePrefixFrom($holder); $path = $this->fileStorageService->upload($filenamePrefix . '/' . $filename, $content); $file = new File($path); $hash = $this->generateFileHash($file); if ($this->isImage($file)) { $this->createThumbnail($file, $hash, $filenamePrefix); } $attachment = $this->factory->create($file, $hash); $holder->addAttachment($attachment); $this->repository->store($attachment); return $attachment; }
/** * Remove Attachment from Comment * @param RemoveCommentAttachmentCommand $command * @return void * @throws \RuntimeException if Comment does not exists or Comment has no particular attachment */ public function removeAttachmentFromComment(RemoveCommentAttachmentCommand $command) { $comment = $this->loadCommentBy($command->commentId); $this->isGranted('EDIT', $comment); $attachment = $comment->getAttachment($command->attachmentId); if (!$attachment) { throw new \RuntimeException('Attachment loading failed. Comment has no such attachment.'); } $comment->removeAttachment($attachment); $this->commentRepository->store($comment); $this->attachmentManager->deleteAttachment($attachment); }
/** * Update certain properties of the Branch * @param Command\UpdatePropertiesCommand $command * @return Branch */ public function updateProperties(Command\UpdatePropertiesCommand $command) { $this->isGranted('EDIT', 'Entity:DiamanteDeskBundle:Branch'); /** * @var $branch \Diamante\DeskBundle\Entity\Branch */ $branch = $this->branchRepository->get($command->id); if (is_null($branch)) { throw new BranchNotFoundException(); } foreach ($command->properties as $name => $value) { $branch->updateProperty($name, $value); } $this->branchRepository->store($branch); return $branch; }
/** * 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; }