/**
  * {@inheritdoc}
  */
 public function apply(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters)
 {
     if ($parameters->has(ResourceOwnerFilter::TYPE)) {
         $this->filtersRegistry->get(ResourceOwnerFilter::TYPE)->apply($dataSource, ResourceOwnerFilter::FIELD, $parameters->get(ResourceOwnerFilter::TYPE), []);
     }
     return $this->filtersApplicator->apply($dataSource, $grid, $parameters);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function getData(Parameters $parameters)
 {
     // Use output walkers option in DoctrineORMAdapter should be false as it affects performance greatly (see #3775)
     $paginator = new Pagerfanta(new DoctrineORMAdapter($this->queryBuilder, true, false));
     $paginator->setCurrentPage($parameters->get('page', 1));
     return $paginator;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function sort(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters)
 {
     $expressionBuilder = $dataSource->getExpressionBuilder();
     $sorting = $parameters->has('sorting') ? $parameters->get('sorting') : $grid->getSorting();
     foreach ($sorting as $field => $direction) {
         $expressionBuilder->addOrderBy($field, $direction);
     }
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function getData(Parameters $parameters)
 {
     $countQueryBuilderModifier = function ($queryBuilder) {
         $queryBuilder->select('COUNT(DISTINCT o.id) AS total_results')->setMaxResults(1);
     };
     $paginator = new Pagerfanta(new DoctrineDbalAdapter($this->queryBuilder, $countQueryBuilderModifier));
     $paginator->setCurrentPage($parameters->get('page', 1));
     return $paginator;
 }
예제 #5
0
 function it_sorts_the_data_source_via_expression_builder_based_on_sorting_parameter(Grid $grid, Parameters $parameters, DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder)
 {
     $parameters->has('sorting')->willReturn(true);
     $parameters->get('sorting')->willReturn(['name' => 'asc']);
     $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
     $grid->getSorting()->willReturn(['name' => 'desc']);
     $expressionBuilder->addOrderBy('name', 'asc')->shouldBeCalled();
     $this->sort($dataSource, $grid, $parameters);
 }
예제 #6
0
파일: Sorter.php 프로젝트: loic425/Sylius
 /**
  * {@inheritdoc}
  */
 public function sort(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters)
 {
     $expressionBuilder = $dataSource->getExpressionBuilder();
     $sorting = $parameters->get('sorting', $grid->getSorting());
     foreach ($sorting as $field => $order) {
         $gridField = $grid->getField($field);
         $property = $gridField->getSortable();
         $expressionBuilder->addOrderBy($property, $order);
     }
 }
 function it_uses_data_provider_to_create_a_view_with_data_and_definition(DataProviderInterface $dataProvider, ParametersParserInterface $parametersParser, Grid $grid, Parameters $parameters, MetadataInterface $resourceMetadata, Request $request, RequestConfiguration $requestConfiguration)
 {
     $expectedResourceGridView = new ResourceGridView(['foo', 'bar'], $grid->getWrappedObject(), $parameters->getWrappedObject(), $resourceMetadata->getWrappedObject(), $requestConfiguration->getWrappedObject());
     $requestConfiguration->getRequest()->willReturn($request);
     $parametersParser->parseRequestValues(['repository' => ['method' => 'createByCustomerQueryBuilder', 'arguments' => ['$customerId']]], $request)->willReturn(['repository' => ['method' => 'createByCustomerQueryBuilder', 'arguments' => [5]]]);
     $grid->getDriverConfiguration()->willReturn(['repository' => ['method' => 'createByCustomerQueryBuilder', 'arguments' => ['$customerId']]]);
     $grid->setDriverConfiguration(['repository' => ['method' => 'createByCustomerQueryBuilder', 'arguments' => [5]]])->shouldBeCalled();
     $dataProvider->getData($grid, $parameters)->willReturn(['foo', 'bar']);
     $this->create($grid, $parameters, $resourceMetadata, $requestConfiguration)->shouldBeSameResourceGridViewAs($expectedResourceGridView);
 }
예제 #8
0
 function it_knows_which_field_it_has_been_sorted_by(Grid $gridDefinition, Parameters $parameters)
 {
     $gridDefinition->hasField('foo')->willReturn(true);
     $gridDefinition->hasField('name')->willReturn(true);
     $gridDefinition->hasField('code')->willReturn(true);
     $gridDefinition->getSorting()->willReturn(['name' => ['path' => 'name', 'direction' => 'desc'], 'code' => ['path' => 'code', 'direction' => 'asc']]);
     $parameters->has('sorting')->willReturn(true);
     $parameters->get('sorting')->willReturn(['code' => ['path' => 'code', 'direction' => 'asc']]);
     $this->isSortedBy('name')->shouldReturn(false);
     $this->isSortedBy('code')->shouldReturn(true);
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function sort(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters)
 {
     $expressionBuilder = $dataSource->getExpressionBuilder();
     $sorting = $parameters->has('sorting') ? $parameters->get('sorting') : $grid->getSorting();
     foreach ($sorting as $field => $options) {
         if (!isset($options['direction'])) {
             $options['direction'] = 'desc';
         }
         $expressionBuilder->addOrderBy($options['path'], $options['direction']);
     }
 }
예제 #10
0
 function it_uses_default_sorting_if_not_provided_in_parameters(Grid $gridDefinition, Parameters $parameters)
 {
     $gridDefinition->hasField('foo')->willReturn(true);
     $gridDefinition->hasField('name')->willReturn(true);
     $gridDefinition->hasField('code')->willReturn(true);
     $gridDefinition->getSorting()->willReturn(['name' => 'desc']);
     $parameters->has('sorting')->willReturn(false);
     $this->isSortedBy('foo')->shouldReturn(false);
     $this->isSortedBy('name')->shouldReturn(true);
     $this->isSortedBy('code')->shouldReturn(false);
     $this->getSortingOrder('name')->shouldReturn('desc');
 }
예제 #11
0
 function it_filters_data_source_based_on_criteria_parameter(ServiceRegistryInterface $filtersRegistry, FilterInterface $stringFilter, Grid $grid, Filter $filter, Parameters $parameters, DataSourceInterface $dataSource)
 {
     $parameters->has('criteria')->willReturn(true);
     $parameters->get('criteria')->willReturn(['keywords' => 'Banana', 'enabled' => true]);
     $grid->hasFilter('keywords')->willReturn(true);
     $grid->hasFilter('enabled')->willReturn(false);
     $grid->getFilter('keywords')->willReturn($filter);
     $filter->getType()->willReturn('string');
     $filter->getOptions()->willReturn(['fields' => ['firstName', 'lastName']]);
     $filtersRegistry->get('string')->willReturn($stringFilter);
     $stringFilter->apply($dataSource, 'keywords', 'Banana', ['fields' => ['firstName', 'lastName']])->shouldBeCalled();
     $this->apply($dataSource, $grid, $parameters);
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function apply(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters)
 {
     if (!$parameters->has('criteria')) {
         return;
     }
     $criteria = $parameters->get('criteria');
     foreach ($criteria as $name => $data) {
         if (!$grid->hasFilter($name)) {
             continue;
         }
         $filter = $grid->getFilter($name);
         $this->filtersRegistry->get($filter->getType())->apply($dataSource, $name, $data, $filter->getOptions());
     }
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function getData(Parameters $parameters)
 {
     $orderBy = $this->queryBuilder->orderBy();
     foreach ($this->expressionBuilder->getOrderBys() as $field => $direction) {
         if (is_int($field)) {
             $field = $direction;
             $direction = 'asc';
         }
         // todo: validate direction?
         $direction = strtolower($direction);
         $orderBy->{$direction}()->field(sprintf('%s.%s', Driver::QB_SOURCE_ALIAS, $field));
     }
     $paginator = new Pagerfanta(new DoctrineODMPhpcrAdapter($this->queryBuilder));
     $paginator->setCurrentPage($parameters->get('page', 1));
     return $paginator;
 }
예제 #14
0
 function it_should_set_the_order_on_the_query_builder_as_fields_only(QueryBuilder $queryBuilder, ExpressionBuilder $expressionBuilder, Parameters $parameters, OrderBy $orderBy, Ordering $ordering)
 {
     $expressionBuilder->getOrderBys()->willReturn(['foo', 'bar']);
     $queryBuilder->orderBy()->willReturn($orderBy);
     $orderBy->asc()->willReturn($ordering);
     $orderBy->asc()->willReturn($ordering);
     $ordering->field('o.foo')->shouldBeCalled();
     $ordering->field('o.bar')->shouldBeCalled();
     $parameters->get('page', 1)->willReturn(1);
     $this->getData($parameters)->shouldHaveType(Pagerfanta::class);
 }
 function it_uses_data_provider_to_create_a_view_with_data_and_definition(DataProviderInterface $dataProvider, Grid $grid, Parameters $parameters, MetadataInterface $resourceMetadata, RequestConfiguration $requestConfiguration)
 {
     $expectedResourceGridView = new ResourceGridView(['foo', 'bar'], $grid->getWrappedObject(), $parameters->getWrappedObject(), $resourceMetadata->getWrappedObject(), $requestConfiguration->getWrappedObject());
     $dataProvider->getData($grid, $parameters)->willReturn(['foo', 'bar']);
     $this->create($grid, $parameters, $resourceMetadata, $requestConfiguration)->shouldBeSameResourceGridViewAs($expectedResourceGridView);
 }
예제 #16
0
 /**
  * @return array|mixed
  */
 private function getCurrentSorting()
 {
     return $this->parameters->has('sorting') ? $this->parameters->get('sorting') : $this->definition->getSorting();
 }
예제 #17
0
파일: DataSource.php 프로젝트: Mozan/Sylius
 /**
  * {@inheritdoc}
  */
 public function getData(Parameters $parameters)
 {
     $paginator = new Pagerfanta(new DoctrineORMAdapter($this->queryBuilder));
     $paginator->setCurrentPage($parameters->get('page', 1));
     return $paginator;
 }
예제 #18
0
 function it_uses_data_provider_to_create_a_view_with_data_and_definition(DataProviderInterface $dataProvider, Grid $grid, Parameters $parameters)
 {
     $expectedGridView = new GridView(['foo', 'bar'], $grid->getWrappedObject(), $parameters->getWrappedObject());
     $dataProvider->getData($grid, $parameters)->willReturn(['foo', 'bar']);
     $this->create($grid, $parameters)->shouldBeSameGridViewAs($expectedGridView);
 }
예제 #19
0
 /**
  * @return array|mixed
  */
 private function getCurrentlySortedBy()
 {
     return $this->parameters->has('sorting') ? array_merge($this->definition->getSorting(), $this->parameters->get('sorting')) : $this->definition->getSorting();
 }