/**
  * Creates Ticket and Message Reference fot it
  *
  * @param $messageId
  * @param $branchId
  * @param $subject
  * @param $description
  * @param $reporter
  * @param $assigneeId
  * @param array $attachments
  * @return \Diamante\DeskBundle\Model\Ticket\Ticket
  * @throws \RuntimeException if unable to load required branch, reporter, assignee
  */
 public function createTicket($messageId, $branchId, $subject, $description, $reporter, $assigneeId, array $attachments = null)
 {
     if (empty($subject)) {
         $subject = self::EMPTY_SUBJECT_PLACEHOLDER;
     }
     $this->ticketBuilder->setSubject($subject)->setDescription($description)->setBranchId($branchId)->setReporter($reporter)->setAssigneeId($assigneeId)->setSource(Source::EMAIL);
     $ticket = $this->ticketBuilder->build();
     if ($attachments) {
         $this->createAttachments($attachments, $ticket);
     }
     $this->ticketRepository->store($ticket);
     $this->createMessageReference($messageId, $ticket);
     $this->em->detach($ticket);
     $this->dispatchEvents($ticket);
     return $ticket;
 }
 /**
  * Create Ticket
  * @param Command\CreateTicketCommand $command
  * @return Ticket
  *
  * @throws ForbiddenException
  */
 public function createTicket(Command\CreateTicketCommand $command)
 {
     $this->isGranted('CREATE', 'Entity:DiamanteDeskBundle:Ticket');
     \Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput');
     $this->ticketBuilder->setSubject($command->subject)->setDescription($command->description)->setBranchId($command->branch)->setReporter($command->reporter)->setAssignee($command->assignee)->setPriority($command->priority)->setSource($command->source)->setStatus($command->status)->setTags($command->tags);
     $ticket = $this->ticketBuilder->build();
     $this->createAttachments($command, $ticket);
     $this->doctrineRegistry->getManager()->persist($ticket);
     $this->doctrineRegistry->getManager()->flush();
     if ($this->loggedUser instanceof OroUser) {
         $this->tagManager->saveTagging($ticket);
         $ticket->setTags(null);
         $this->loadTagging($ticket);
     }
     $this->dispatchWorkflowEvent($this->doctrineRegistry, $this->dispatcher, $ticket);
     return $ticket;
 }
 /**
  * Create Ticket
  * @param CreateTicketCommand $command
  * @return \Diamante\DeskBundle\Model\Ticket\Ticket
  * @throws \RuntimeException if unable to load required branch, reporter, assignee
  */
 public function createTicket(CreateTicketCommand $command)
 {
     $this->isGranted('CREATE', 'Entity:DiamanteDeskBundle:Ticket');
     \Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput');
     $this->ticketBuilder->setSubject($command->subject)->setDescription($command->description)->setBranchId($command->branch)->setReporter($command->reporter)->setAssigneeId($command->assignee)->setPriority($command->priority)->setSource($command->source)->setStatus($command->status)->setTags($command->tags);
     $ticket = $this->ticketBuilder->build();
     if (is_array($command->attachmentsInput) && false === empty($command->attachmentsInput)) {
         foreach ($command->attachmentsInput as $each) {
             $this->attachmentManager->createNewAttachment($each->getFilename(), $each->getContent(), $ticket);
         }
     }
     $this->ticketRepository->store($ticket);
     if ($this->securityFacade->getOrganization()) {
         $this->tagManager->saveTagging($ticket);
     }
     $this->em->detach($ticket);
     $this->dispatchEvents($ticket);
     return $ticket;
 }