getCriteria() public method

public getCriteria ( array $criteria = [] ) : array
$criteria array
return array
Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function getResources(RequestConfiguration $requestConfiguration, RepositoryInterface $repository)
 {
     $repositoryMethod = $requestConfiguration->getRepositoryMethod();
     if (null !== $repositoryMethod) {
         $arguments = array_values($requestConfiguration->getRepositoryArguments());
         return $repository->{$repositoryMethod}(...$arguments);
     }
     if (!$requestConfiguration->isPaginated() && !$requestConfiguration->isLimited()) {
         return $repository->findAll();
     }
     if (!$requestConfiguration->isPaginated()) {
         return $repository->findBy($requestConfiguration->getCriteria(), $requestConfiguration->getSorting(), $requestConfiguration->getLimit());
     }
     return $repository->createPaginator($requestConfiguration->getCriteria(), $requestConfiguration->getSorting());
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function getResources(RequestConfiguration $requestConfiguration, RepositoryInterface $repository)
 {
     if (null !== ($repositoryMethod = $requestConfiguration->getRepositoryMethod())) {
         $callable = [$repository, $repositoryMethod];
         $resources = call_user_func_array($callable, $requestConfiguration->getRepositoryArguments());
         return $resources;
     }
     if (!$requestConfiguration->isPaginated() && !$requestConfiguration->isLimited()) {
         return $repository->findBy($requestConfiguration->getCriteria(), $requestConfiguration->getSorting());
     }
     if (!$requestConfiguration->isPaginated()) {
         return $repository->findBy($requestConfiguration->getCriteria(), $requestConfiguration->getSorting(), $requestConfiguration->getLimit());
     }
     return $repository->createPaginator($requestConfiguration->getCriteria(), $requestConfiguration->getSorting());
 }
 function it_creates_paginator_by_default(RequestConfiguration $requestConfiguration, RepositoryInterface $repository, Pagerfanta $paginator)
 {
     $requestConfiguration->isHtmlRequest()->willReturn(true);
     $requestConfiguration->getRepositoryMethod()->willReturn(null);
     $requestConfiguration->isPaginated()->willReturn(true);
     $requestConfiguration->getPaginationMaxPerPage()->willReturn(5);
     $requestConfiguration->isLimited()->willReturn(false);
     $requestConfiguration->getCriteria()->willReturn([]);
     $requestConfiguration->getSorting()->willReturn([]);
     $repository->createPaginator([], [])->willReturn($paginator);
     $this->getResources($requestConfiguration, $repository)->shouldReturn($paginator);
 }
 /**
  * {@inheritdoc}
  */
 public function get(RequestConfiguration $requestConfiguration, RepositoryInterface $repository)
 {
     if (null !== ($repositoryMethod = $requestConfiguration->getRepositoryMethod())) {
         $callable = [$repository, $repositoryMethod];
         return call_user_func_array($callable, $requestConfiguration->getRepositoryArguments());
     }
     if (!$requestConfiguration->isPaginated() && !$requestConfiguration->isLimited()) {
         return $repository->findAll();
     }
     if (!$requestConfiguration->isPaginated()) {
         return $repository->findBy($requestConfiguration->getCriteria(), $requestConfiguration->getSorting(), $requestConfiguration->getLimit());
     }
     $request = $requestConfiguration->getRequest();
     /** @var Pagerfanta $paginator */
     $paginator = $repository->createPaginator($requestConfiguration->getCriteria(), $requestConfiguration->getSorting());
     $paginator->setCurrentPage($request->query->get('page', 1));
     if (!$requestConfiguration->isHtmlRequest()) {
         $route = new Route($request->attributes->get('_route'), array_merge($request->attributes->get('_route_params'), $request->query->all()));
         return $this->pagerfantaRepresentationFactory->createRepresentation($paginator, $route);
     }
     return $paginator;
 }
 /**
  * {@inheritdoc}
  */
 public function get(RequestConfiguration $requestConfiguration, RepositoryInterface $repository)
 {
     if ($requestConfiguration->hasPermission() && $this->requireOwnerCheck($vars = $requestConfiguration->getVars())) {
         $owner = $this->currentIdentityProvider->getIdentity();
         $ownerField = is_bool($vars['acl_owner']) ? ResourceOwnerFilter::FIELD : $vars['acl_owner'];
         // using in grid param
         $requestConfiguration->getRequest()->query->set(ResourceOwnerFilter::TYPE, $owner);
         $criteria = $requestConfiguration->getCriteria();
         $criteria[$ownerField] = $owner;
         $requestConfiguration->getParameters()->set('criteria', $criteria);
     }
     return $this->decoratedResolver->get($requestConfiguration, $repository);
 }
 /**
  * {@inheritdoc}
  */
 public function get(RequestConfiguration $requestConfiguration, RepositoryInterface $repository)
 {
     if (null !== ($repositoryMethod = $requestConfiguration->getRepositoryMethod())) {
         $callable = [$repository, $repositoryMethod];
         return call_user_func_array($callable, $requestConfiguration->getRepositoryArguments());
     }
     $criteria = [];
     $request = $requestConfiguration->getRequest();
     if ($request->attributes->has('id')) {
         return $repository->find($request->attributes->get('id'));
     }
     if ($request->attributes->has('slug')) {
         $criteria = ['slug' => $request->attributes->get('slug')];
     }
     $criteria = array_merge($criteria, $requestConfiguration->getCriteria());
     return $repository->findOneBy($criteria);
 }
 /**
  * {@inheritdoc}
  */
 public function get(RequestConfiguration $requestConfiguration, RepositoryInterface $repository)
 {
     $repositoryMethod = $requestConfiguration->getRepositoryMethod();
     if (null !== $repositoryMethod) {
         $arguments = array_values($requestConfiguration->getRepositoryArguments());
         return $repository->{$repositoryMethod}(...$arguments);
     }
     $criteria = [];
     $request = $requestConfiguration->getRequest();
     if ($request->attributes->has('id')) {
         return $repository->find($request->attributes->get('id'));
     }
     if ($request->attributes->has('slug')) {
         $criteria = ['slug' => $request->attributes->get('slug')];
     }
     $criteria = array_merge($criteria, $requestConfiguration->getCriteria());
     return $repository->findOneBy($criteria);
 }
 function it_creates_a_pagniated_respresentation_for_pagerfanta_for_non_html_requests(RequestConfiguration $requestConfiguration, RepositoryInterface $repository, Pagerfanta $paginator, Request $request, ParameterBag $queryParameters, ParameterBag $requestAttributes, PagerfantaFactory $pagerfantaRepresentationFactory, PaginatedRepresentation $paginatedRepresentation)
 {
     $requestConfiguration->isHtmlRequest()->willReturn(false);
     $requestConfiguration->getRepositoryMethod()->willReturn(null);
     $requestConfiguration->isPaginated()->willReturn(true);
     $requestConfiguration->isLimited()->willReturn(false);
     $requestConfiguration->getCriteria()->willReturn(array());
     $requestConfiguration->getSorting()->willReturn(array());
     $repository->createPaginator(array(), array())->willReturn($paginator);
     $requestConfiguration->getRequest()->willReturn($request);
     $request->query = $queryParameters;
     $queryParameters->get('page', 1)->willReturn(6);
     $queryParameters->all()->willReturn(array('foo' => 2, 'bar' => 15));
     $request->attributes = $requestAttributes;
     $requestAttributes->get('_route')->willReturn('sylius_product_index');
     $requestAttributes->get('_route_params')->willReturn(array('slug' => 'foo-bar'));
     $paginator->setCurrentPage(6)->shouldBeCalled();
     $pagerfantaRepresentationFactory->createRepresentation($paginator, Argument::type(Route::class))->willReturn($paginatedRepresentation);
     $this->get($requestConfiguration, $repository)->shouldReturn($paginatedRepresentation);
 }
 function it_can_find_specific_resource_with_merged_custom_criteria_overwriting_the_attributes(RequestConfiguration $requestConfiguration, Request $request, ParameterBag $requestAttributes, RepositoryInterface $repository, ResourceInterface $resource)
 {
     $requestConfiguration->getCriteria()->willReturn(['id' => 5]);
     $requestConfiguration->getRepositoryMethod()->willReturn(null);
     $requestConfiguration->getRequest()->willReturn($request);
     $request->attributes = $requestAttributes;
     $requestAttributes->has('id')->willReturn(false);
     $requestAttributes->has('slug')->willReturn(false);
     $repository->findOneBy(['id' => 5])->willReturn($resource);
     $this->get($requestConfiguration, $repository)->shouldReturn($resource);
 }