/** * @param FilterCriteriaProcessor $processor * @param FilterableRepository $repository * @param FilteringCommand $command * @param ApiPagingService $service * * @return \Diamante\DeskBundle\Model\Shared\Filter\PagingProperties */ protected function buildPagination(FilterCriteriaProcessor $processor, FilterableRepository $repository, FilteringCommand $command, ApiPagingService $service) { $processor->setCommand($command); $criteria = $processor->getCriteria(); $pagingProperties = $processor->getPagingProperties(); $pagingInfo = $service->getPagingInfo($repository, $pagingProperties, $criteria); $this->populatePagingHeaders($service, $pagingInfo); return $pagingProperties; }
/** * @test */ public function testBranchesAreFiltered() { $branches = array(new Branch('DUMM', 'DUMMY_NAME_1', 'DUMMY_DESC_1'), new Branch('DUMMY', 'DUMMY_NAME_2', 'DUMMY_DESC_2')); $pagingInfo = new PagingInfo(1, new FilterPagingProperties()); $command = new FilterBranchesCommand(); $command->name = 'NAME_2'; $this->branchRepository->expects($this->once())->method('filter')->with($this->equalTo(array(array('name', 'like', 'NAME_2'))), $this->equalTo(new FilterPagingProperties()))->will($this->returnValue(array($branches[0]))); $this->apiPagingService->expects($this->once())->method('getPagingInfo')->will($this->returnValue($pagingInfo)); $retrievedBranches = $this->branchServiceImpl->listAllBranches($command); $this->assertNotNull($retrievedBranches); $this->assertTrue(is_array($retrievedBranches)); $this->assertNotEmpty($retrievedBranches); $this->assertEquals($branches[0], $retrievedBranches[0]); }
/** * Retrieves list of all Branches. Filters branches with parameters provided within GET request * Time filtering parameters as well as paging/sorting configuration parameters can be found in \Diamante\DeskBundle\Api\Command\CommonFilterCommand class. * Time filtering values should be converted to UTC * * @ApiDoc( * description="Returns all branches", * uri="/branches.{_format}", * method="GET", * resource=true, * statusCodes={ * 200="Returned when successful", * 403="Returned when the user is not authorized to list branches" * } * ) * @param Command\Filter\FilterBranchesCommand $command|null * @return \Diamante\DeskBundle\Model\Branch\Branch[] */ public function listAllBranches(Command\Filter\FilterBranchesCommand $command = null) { $processor = new BranchFilterCriteriaProcessor(); $processor->setCommand($command); $criteria = $processor->getCriteria(); $pagingProperties = $processor->getPagingProperties(); $repository = $this->getBranchRepository(); $branches = $repository->filter($criteria, $pagingProperties); try { $pagingInfo = $this->apiPagingService->getPagingInfo($repository, $pagingProperties, $criteria); $this->populatePagingHeaders($this->apiPagingService, $pagingInfo); } catch (\Exception $e) { } return $branches; }
/** * Retrieves list of all Articles. * * @ApiDoc( * description="Returns all articles", * uri="/articles.{_format}", * method="GET", * resource=true, * statusCodes={ * 200="Returned when successful", * 403="Returned when the user is not authorized to list branches" * } * ) * @return \Diamante\DeskBundle\Model\Article\Article[] */ public function listAllArticles(Command\Filter\FilterArticlesCommand $command) { $user = $this->getAuthorizationService()->getLoggedUser(); if ($user instanceof ApiUser) { // @TODO Change to constants $command->status = 1; } $criteriaProcessor = new ArticleFilterCriteriaProcessor(); $repository = $this->getRepository(); $pagingProperties = $this->buildPagination($criteriaProcessor, $repository, $command, $this->apiPagingService); $criteria = $criteriaProcessor->getCriteria(); $articles = $repository->filter($criteria, $pagingProperties); $pagingInfo = $this->apiPagingService->getPagingInfo($repository, $pagingProperties, $criteria); $this->populatePagingHeaders($this->apiPagingService, $pagingInfo); return $articles; }
/** * @test */ public function testPopulatePagingHeaders() { $pathToLinkMapping = [[$this->createPageLink(1), self::DUMMY_SERVER . $this->createPageLink(1)], [$this->createPageLink(6), self::DUMMY_SERVER . $this->createPageLink(6)], [$this->createPageLink(4), self::DUMMY_SERVER . $this->createPageLink(4)], [$this->createPageLink(2), self::DUMMY_SERVER . $this->createPageLink(2)]]; $linksString = $this->getLinksString($pathToLinkMapping); $expectedHeaders = array('link' => array($linksString), 'x-total' => array(150)); $headers = new HeaderBag(); $this->pagingProvider->expects($this->exactly(2))->method('getContext')->will($this->returnValue($this->pagingContext)); $this->pagingContext->expects($this->exactly(2))->method('getHeaderContainer')->will($this->returnValue($headers)); $this->pagingInfo->expects($this->once())->method('getTotalRecords')->will($this->returnValue(150)); $this->apiPagingServiceImpl->populatePagingHeaders($this->pagingInfo, $linksString); $this->assertEquals($expectedHeaders, $headers->all()); }
/** * Retrieves list of Tickets found by query. Ticket is searched by subject and description. * 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 found tickets.", * uri="/tickets/search.{_format}", * method="GET", * resource=true, * statusCodes={ * 200="Returned when successful", * 403="Returned when the user is not authorized to search tickets" * } * ) * * @param Command\SearchTicketsCommand $searchTicketsCommand * @return \Diamante\DeskBundle\Entity\Ticket[] */ public function searchTickets(Command\SearchTicketsCommand $searchTicketsCommand) { $searchProcessor = new TicketSearchProcessor(); $searchProcessor->setCommand($searchTicketsCommand); $query = $searchProcessor->getSearchQuery(); $criteria = $searchProcessor->getCriteria(); $pagingProperties = $searchProcessor->getPagingProperties(); $repository = $this->getTicketRepository(); $tickets = $repository->search($query, $criteria, $pagingProperties); $pagingInfo = $this->apiPagingService->getPagingInfo($repository, $pagingProperties, $criteria); $this->populatePagingHeaders($this->apiPagingService, $pagingInfo); return $tickets; }
public function testCommentsFiltered() { $comments = array(new Comment("DUMMY_CONTENT_1", $this->_dummyTicket, $this->createAuthor(), false), new Comment("DUMMY_CONTENT_2", $this->_dummyTicket, $this->createAuthor(), false)); $command = new FilterCommentsCommand(); $command->author = 'oro_1'; $pagingInfo = new PagingInfo(1, new FilterPagingProperties()); $this->commentRepository->expects($this->once())->method('filter')->with($this->equalTo(array(array('author', 'eq', 'oro_1'))), $this->equalTo(new FilterPagingProperties()))->will($this->returnValue(array($comments[1]))); $this->apiPagingService->expects($this->once())->method('getPagingInfo')->will($this->returnValue($pagingInfo)); $retrievedComments = $this->service->listAllComments($command); $this->assertNotNull($retrievedComments); $this->assertTrue(is_array($retrievedComments)); $this->assertNotEmpty($retrievedComments); $this->assertEquals($comments[1], $retrievedComments[0]); }
/** * @test */ public function testSearchTickets() { $tickets = array(new Ticket(new UniqueId('unique_id'), new TicketSequenceNumber(13), self::SUBJECT, self::DESCRIPTION, $this->createBranch(), new User(1, User::TYPE_DIAMANTE), $this->createAssignee(), new Source(Source::PHONE), new Priority(Priority::PRIORITY_LOW), new Status(Status::CLOSED)), new Ticket(new UniqueId('unique_id'), new TicketSequenceNumber(12), self::SUBJECT, self::DESCRIPTION, $this->createBranch(), new User(1, User::TYPE_ORO), $this->createAssignee(), new Source(Source::PHONE), new Priority(Priority::PRIORITY_LOW), new Status(Status::CLOSED))); $command = new SearchTicketsCommand(); $command->q = 'scr'; $command->reporter = 'oro_1'; $pagingInfo = new PagingInfo(1, new FilterPagingProperties()); $this->ticketRepository->expects($this->once())->method('search')->with($this->equalTo('scr'), $this->equalTo(array(array('reporter', 'eq', 'oro_1'))), $this->equalTo(new FilterPagingProperties()))->will($this->returnValue(array($tickets[1]))); $this->apiPagingService->expects($this->once())->method('getPagingInfo')->will($this->returnValue($pagingInfo)); $retrievedTickets = $this->ticketService->searchTickets($command); $this->assertNotNull($retrievedTickets); $this->assertTrue(is_array($retrievedTickets)); $this->assertNotEmpty($retrievedTickets); $this->assertEquals($tickets[1], $retrievedTickets[0]); }
/** * @param ApiPagingService $service * @param PagingInfo $info */ protected function populatePagingHeaders(ApiPagingService $service, PagingInfo $info) { $links = $service->createPagingLinks($info); $service->populatePagingHeaders($info, $links); }