function it_filters_data_source_based_on_criteria_parameter(ServiceRegistryInterface $filtersRegistry, FilterInterface $stringFilter, Grid $grid, Filter $filter, DataSourceInterface $dataSource) { $parameters = new Parameters(['criteria' => ['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); }
/** * {@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()); } }