/**
  * Retrieves list of all Tickets. Performs filtering of tickets if provided with criteria as GET parameters.
  * Time filtering parameters as well as paging/sorting configuration parameters can be found in \Diamante\DeskBundle\Api\Command\Filter\CommonFilterCommand class.
  * Time filtering values should be converted to UTC
  *
  * @ApiDoc(
  *  description="Returns all tickets.",
  *  uri="/tickets.{_format}",
  *  method="GET",
  *  resource=true,
  *  statusCodes={
  *      200="Returned when successful",
  *      403="Returned when the user is not authorized to list tickets"
  *  }
  * )
  *
  * @param Command\Filter\FilterTicketsCommand $ticketFilterCommand
  * @return \Diamante\DeskBundle\Entity\Ticket[]
  */
 public function listAllTickets(Command\Filter\FilterTicketsCommand $ticketFilterCommand)
 {
     $criteriaProcessor = new TicketFilterCriteriaProcessor();
     $criteriaProcessor->setCommand($ticketFilterCommand);
     $criteria = $criteriaProcessor->getCriteria();
     $pagingProperties = $criteriaProcessor->getPagingProperties();
     $repository = $this->getTicketRepository();
     $user = $this->getAuthorizationService()->getLoggedUser();
     if ($user instanceof ApiUser) {
         $user = $this->userService->getUserFromApiUser($user);
     }
     $tickets = $repository->filter($criteria, $pagingProperties, $user);
     try {
         $pagingInfo = $this->apiPagingService->getPagingInfo($repository, $pagingProperties, $criteria);
         $this->populatePagingHeaders($this->apiPagingService, $pagingInfo);
     } catch (\Exception $e) {
     }
     return $tickets;
 }
 /**
  * Verify permissions through Oro Platform security bundle
  *
  * @param string $operation
  * @param Comment|string $entity
  * @throws ForbiddenException
  */
 private function isGranted($operation, $entity)
 {
     // User should have ability to view all comments (except private)
     // if he is an owner of a ticket
     if ($operation === 'VIEW' && is_object($entity)) {
         if ($this->authorizationService->getLoggedUser()) {
             $loggedUser = $this->authorizationService->getLoggedUser();
             if ($loggedUser instanceof ApiUser) {
                 $loggedUser = $this->userService->getUserFromApiUser($loggedUser);
             }
             /** @var User $reporter */
             $reporter = $entity->getTicket()->getReporter();
             if ($loggedUser && $reporter && $loggedUser->getId() == $reporter->getId()) {
                 return;
             }
         }
     }
     if (!$this->authorizationService->isActionPermitted($operation, $entity)) {
         throw new ForbiddenException("Not enough permissions.");
     }
 }
 /**
  * Retrieves list of all Tickets. Performs filtering of tickets if provided with criteria as GET parameters.
  * Time filtering parameters as well as paging/sorting configuration parameters can be found in \Diamante\DeskBundle\Api\Command\Filter\CommonFilterCommand class.
  * Time filtering values should be converted to UTC
  *
  * @ApiDoc(
  *  description="Returns all tickets.",
  *  uri="/tickets.{_format}",
  *  method="GET",
  *  resource=true,
  *  statusCodes={
  *      200="Returned when successful",
  *      403="Returned when the user is not authorized to list tickets"
  *  }
  * )
  *
  * @param Command\Filter\FilterTicketsCommand $ticketFilterCommand
  * @return \Diamante\DeskBundle\Entity\Ticket[]
  */
 public function listAllTickets(Command\Filter\FilterTicketsCommand $ticketFilterCommand)
 {
     $criteriaProcessor = new TicketFilterCriteriaProcessor();
     $repository = $this->getTicketRepository();
     $user = $this->getAuthorizationService()->getLoggedUser();
     if ($user instanceof ApiUser) {
         $user = $this->userService->getUserFromApiUser($user);
     }
     if ($user instanceof DiamanteUser) {
         $userType = User::TYPE_DIAMANTE;
     } else {
         $userType = User::TYPE_ORO;
     }
     $strategyProvider = new StrategyProvider(new User($user->getId(), $userType));
     $strategy = $strategyProvider->getStrategy();
     $pagingProperties = $this->buildPagination($criteriaProcessor, $repository, $ticketFilterCommand, $this->apiPagingService, $strategy->getCountCallback());
     $criteria = $criteriaProcessor->getCriteria();
     $tickets = $repository->filter($criteria, $pagingProperties, $strategy->getFilterCallback());
     $tickets = $strategy->afterResult($tickets, $this->tagManager);
     return $tickets;
 }
 /**
  * Retrieves list of all Tickets. Performs filtering of tickets if provided with criteria as GET parameters.
  * Time filtering parameters as well as paging/sorting configuration parameters can be found in \Diamante\DeskBundle\Api\Command\Filter\CommonFilterCommand class.
  * Time filtering values should be converted to UTC
  *
  * @ApiDoc(
  *  description="Returns all tickets.",
  *  uri="/tickets.{_format}",
  *  method="GET",
  *  resource=true,
  *  statusCodes={
  *      200="Returned when successful",
  *      403="Returned when the user is not authorized to list tickets"
  *  }
  * )
  *
  * @param Command\Filter\FilterTicketsCommand $ticketFilterCommand
  * @return \Diamante\DeskBundle\Entity\Ticket[]
  */
 public function listAllTickets(Command\Filter\FilterTicketsCommand $ticketFilterCommand)
 {
     $criteriaProcessor = new TicketFilterCriteriaProcessor();
     $repository = $this->getTicketRepository();
     $user = $this->getAuthorizationService()->getLoggedUser();
     if ($user instanceof ApiUser) {
         $user = $this->userService->getUserFromApiUser($user);
     }
     $pagingProperties = $this->buildPagination($criteriaProcessor, $repository, $ticketFilterCommand, $this->apiPagingService);
     $criteria = $criteriaProcessor->getCriteria();
     $tickets = $repository->filter($criteria, $pagingProperties, $user);
     if ($this->loggedUser instanceof OroUser) {
         foreach ($tickets as $ticket) {
             /** @var Ticket $ticket */
             $this->tagManager->loadTagging($ticket);
         }
     }
     $pagingInfo = $this->apiPagingService->getPagingInfo($repository, $pagingProperties, $criteria);
     $this->populatePagingHeaders($this->apiPagingService, $pagingInfo);
     return $tickets;
 }