/**
  * @param int $ticketId
  * @return Ticket
  *
  * @throws TicketNotFoundException
  */
 private function loadTicketBy($ticketId)
 {
     $ticket = $this->ticketRepository->get($ticketId);
     if (is_null($ticket)) {
         throw new TicketNotFoundException();
     }
     return $ticket;
 }
 /**
  * @param int $ticketId
  * @return Ticket
  */
 private function loadTicketBy($ticketId)
 {
     $ticket = $this->ticketRepository->get($ticketId);
     if (is_null($ticket)) {
         throw new \RuntimeException('Ticket loading failed, ticket not found.');
     }
     return $ticket;
 }
 /**
  * @param int $id
  * @return $this
  */
 public function setBranchId($id)
 {
     $branch = $this->branchRepository->get((int) $id);
     if (is_null($branch)) {
         throw new \LogicException('Branch loading failed, branch not found.');
     }
     $this->branch = $branch;
     return $this;
 }
 /**
  * @param string $filterId
  * @return mixed
  */
 public function generateGridFilterUrl($filterId)
 {
     /**
      * @var $filter \Diamante\DeskBundle\Model\Ticket\Filter
      */
     $filter = $this->filterRepository->get($filterId);
     if (!$filter) {
         throw new \RuntimeException('Filter loading failed, filter not found.');
     }
     $concreteFilterUrlGenerator = $this->container->get($filter->getServiceId());
     if (!$concreteFilterUrlGenerator) {
         throw new \RuntimeException('Filter generator loading failed, filter generator not found.');
     }
     if (!$concreteFilterUrlGenerator instanceof FilterUrlGeneratorInterface) {
         throw new \InvalidArgumentException(sprintf('Object should be an instance of FilterUrlGeneratorInterface.'));
     }
     return $concreteFilterUrlGenerator->generateFilterUrlPart();
 }
 /**
  * Create Ticket
  *
  * @ApiDoc(
  *  description="Create ticket",
  *  uri="/tickets.{_format}",
  *  method="POST",
  *  resource=true,
  *  statusCodes={
  *      201="Returned when successful",
  *      403="Returned when the user is not authorized to create ticket"
  *  }
  * )
  *
  * @param CreateTicketCommand $command
  * @return \Diamante\DeskBundle\Model\Ticket\Ticket
  */
 public function createTicket(CreateTicketCommand $command)
 {
     if (empty($command->assignee)) {
         $branch = $this->branchRepository->get((int) $command->branch);
         if ($branch) {
             $command->assignee = $branch->getDefaultAssigneeId();
         }
     }
     $this->prepareAttachmentInput($command);
     return parent::createTicket($command);
 }
 /**
  * @param $branchId
  * @return int
  */
 public function getBranchDefaultAssignee($branchId)
 {
     /**
      * @var $branch \Diamante\DeskBundle\Model\Branch\Branch
      */
     $branch = $this->branchRepository->get($branchId);
     if (empty($branch)) {
         throw new \RuntimeException('No branch with given ID found');
     }
     return $branch->getDefaultAssigneeId();
 }
 /**
  * Delete Branch
  * @param int $branchId
  * @return void
  */
 public function deleteBranch($branchId)
 {
     $this->isGranted('DELETE', 'Entity:DiamanteDeskBundle:Branch');
     $branch = $this->branchRepository->get($branchId);
     if (is_null($branch)) {
         throw new \RuntimeException('Branch loading failed, branch not found. ');
     }
     if ($branch->getLogo()) {
         $this->branchLogoHandler->remove($branch->getLogo());
     }
     $this->branchRepository->remove($branch);
 }
 /**
  * Delete Branch
  * @param int $branchId
  * @return void
  */
 public function deleteBranch($branchId)
 {
     $this->isGranted('DELETE', 'Entity:DiamanteDeskBundle:Branch');
     /** @var Branch $branch */
     $branch = $this->branchRepository->get($branchId);
     if (is_null($branch)) {
         throw new BranchNotFoundException();
     }
     if ($branch->getLogo()) {
         $this->branchLogoHandler->remove($branch->getLogo());
     }
     $this->branchRepository->remove($branch);
 }
 /**
  * Create Ticket
  *
  * @ApiDoc(
  *  description="Create ticket",
  *  uri="/tickets.{_format}",
  *  method="POST",
  *  resource=true,
  *  statusCodes={
  *      201="Returned when successful",
  *      403="Returned when the user is not authorized to create ticket"
  *  }
  * )
  *
  * @param CreateTicketCommand $command
  * @return \Diamante\DeskBundle\Model\Ticket\Ticket
  */
 public function createTicket(CreateTicketCommand $command)
 {
     if (0 === $command->branch) {
         $command->branch = (int) $this->configManager->get('diamante_email_processing.default_branch');
     }
     if (empty($command->assignee)) {
         $branch = $this->branchRepository->get((int) $command->branch);
         if ($branch) {
             $command->assignee = $branch->getDefaultAssigneeId();
         }
     }
     $this->prepareAttachmentInput($command);
     return parent::createTicket($command);
 }