function it_does_not_filters_when_data_id_is_not_defined(DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder)
 {
     $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
     $expressionBuilder->equals('entity', Argument::any())->shouldNotBeCalled();
     $dataSource->restrict(Argument::any())->shouldNotBeCalled();
     $this->apply($dataSource, 'entity', '', []);
 }
Beispiel #2
1
 /**
  * {@inheritdoc}
  */
 public function apply(DataSourceInterface $dataSource, $name, $data, array $options)
 {
     $expressionBuilder = $dataSource->getExpressionBuilder();
     if (is_array($data) && !isset($data['type'])) {
         $data['type'] = isset($options['type']) ? $options['type'] : self::TYPE_CONTAINS;
     }
     if (!is_array($data)) {
         $data = ['type' => self::TYPE_CONTAINS, 'value' => $data];
     }
     $fields = array_key_exists('fields', $options) ? $options['fields'] : [$name];
     $type = $data['type'];
     $value = array_key_exists('value', $data) ? $data['value'] : null;
     if (!in_array($type, [self::TYPE_NOT_EMPTY, self::TYPE_EMPTY], true) && '' === trim($value)) {
         return;
     }
     if (1 === count($fields)) {
         $dataSource->restrict($this->getExpression($expressionBuilder, $type, current($fields), $value));
         return;
     }
     $expressions = [];
     foreach ($fields as $field) {
         $expressions[] = $this->getExpression($expressionBuilder, $type, $field, $value);
     }
     $dataSource->restrict($expressionBuilder->orX(...$expressions));
 }
Beispiel #3
0
 function it_filters_false_boolean_values(DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder)
 {
     $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
     $expressionBuilder->equals('enabled', false)->willReturn('EXPR');
     $dataSource->restrict('EXPR')->shouldBeCalled();
     $this->apply($dataSource, 'enabled', BooleanFilter::FALSE, []);
 }
 function it_filters_date_from_to(DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder)
 {
     $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
     $expressionBuilder->greaterThanOrEqual('checkoutCompletedAt', '2016-12-05 08:00')->shouldBeCalled();
     $expressionBuilder->lessThan('checkoutCompletedAt', '2016-12-06 08:00')->shouldBeCalled();
     $this->apply($dataSource, 'checkoutCompletedAt', ['from' => ['date' => '2016-12-05', 'time' => '08:00'], 'to' => ['date' => '2016-12-06', 'time' => '08:00']], []);
 }
 /**
  * {@inheritdoc}
  */
 public function apply(DataSourceInterface $dataSource, $name, $data, array $options)
 {
     if (empty($data)) {
         return;
     }
     $field = isset($options['field']) ? $options['field'] : $name;
     $dataSource->restrict($dataSource->getExpressionBuilder()->equals($field, $data));
 }
Beispiel #6
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);
     }
 }
Beispiel #7
0
 function it_sorts_the_data_source_via_expression_builder_based_on_sorting_parameter(Grid $grid, DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder)
 {
     $parameters = new Parameters(['sorting' => ['name' => ['direction' => 'asc']]]);
     $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
     $grid->getSorting()->willReturn(['name' => ['path' => 'translation.name', 'direction' => 'desc']]);
     $expressionBuilder->addOrderBy('translation.name', 'asc')->shouldBeCalled();
     $this->sort($dataSource, $grid, $parameters);
 }
Beispiel #8
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);
 }
Beispiel #9
0
 /**
  * {@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);
     }
 }
Beispiel #10
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']);
     }
 }
Beispiel #11
0
 function it_sorts_the_data_source_via_expression_builder_based_on_sorting_parameter(Grid $grid, Field $nameField, DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder)
 {
     $parameters = new Parameters(['sorting' => ['name' => 'asc']]);
     $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
     $grid->getSorting()->willReturn(['code' => 'desc']);
     $grid->hasField('name')->willReturn(true);
     $grid->getField('name')->willReturn($nameField);
     $nameField->isSortable()->willReturn(true);
     $nameField->getSortable()->willReturn('translation.name');
     $expressionBuilder->addOrderBy('translation.name', 'asc')->shouldBeCalled();
     $this->sort($dataSource, $grid, $parameters);
 }
Beispiel #12
0
 /**
  * {@inheritdoc}
  */
 public function apply(DataSourceInterface $dataSource, $name, $data, array $options)
 {
     if (empty($data)) {
         return;
     }
     $fields = isset($options['fields']) ? $options['fields'] : [$name];
     $expressionBuilder = $dataSource->getExpressionBuilder();
     $expressions = [];
     foreach ($fields as $field) {
         $expressions[] = $expressionBuilder->equals($field, $data);
     }
     $dataSource->restrict($expressionBuilder->orX(...$expressions));
 }
Beispiel #13
0
 /**
  * {@inheritdoc}
  */
 public function apply(DataSourceInterface $dataSource, $name, $data, array $options)
 {
     $expressionBuilder = $dataSource->getExpressionBuilder();
     $field = isset($options['field']) ? $options['field'] : $name;
     $from = $this->getDateTime($data['from']);
     if (null !== $from) {
         $expressionBuilder->greaterThanOrEqual($field, $from);
     }
     $to = $this->getDateTime($data['to']);
     if (null !== $to) {
         $expressionBuilder->lessThan($field, $to);
     }
 }
Beispiel #14
0
 /**
  * {@inheritdoc}
  */
 public function apply(DataSourceInterface $dataSource, $name, $data, array $options)
 {
     $expressionBuilder = $dataSource->getExpressionBuilder();
     if (!is_array($data)) {
         $data = ['type' => self::TYPE_CONTAINS, 'value' => $data];
     }
     $fields = array_key_exists('fields', $options) ? $options['fields'] : [$name];
     $type = $data['type'];
     $value = array_key_exists('value', $data) ? $data['value'] : null;
     if (1 === count($fields)) {
         $expression = $this->getExpression($expressionBuilder, $type, $name, $value);
     } else {
         $expressions = [];
         foreach ($fields as $field) {
             $expressions[] = $this->getExpression($expressionBuilder, $type, $field, $value);
         }
         $expression = $expressionBuilder->orX($expressions);
     }
     $dataSource->restrict($expression);
 }
Beispiel #15
0
 function it_filters_in_multiple_fields(DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder)
 {
     $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
     $expressionBuilder->like('firstName', '%John%')->willReturn('EXPR1');
     $expressionBuilder->like('lastName', '%John%')->willReturn('EXPR2');
     $expressionBuilder->orX(['EXPR1', 'EXPR2'])->willReturn('EXPR');
     $dataSource->restrict('EXPR')->shouldBeCalled();
     $this->apply($dataSource, 'name', 'John', ['fields' => ['firstName', 'lastName']]);
 }
Beispiel #16
0
 function it_filters_translation_fields(DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder)
 {
     $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
     $expressionBuilder->like('translation.name', '%John%')->willReturn('EXPR');
     $dataSource->restrict('EXPR')->shouldBeCalled();
     $this->apply($dataSource, 'name', 'John', ['fields' => ['translation.name']]);
 }
Beispiel #17
0
 function it_does_not_ignore_filter_if_its_value_is_zero(DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder)
 {
     $dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
     $expressionBuilder->like('firstName', '%0%')->willReturn('EXPR');
     $dataSource->restrict('EXPR')->shouldBeCalled();
     $this->apply($dataSource, 'firstName', ['type' => StringFilter::TYPE_CONTAINS, 'value' => '0'], []);
 }