@@ 15-70 (lines=56) @@ | ||
12 | use Symfony\Component\Form\FormBuilderInterface; |
|
13 | use Symfony\Component\OptionsResolver\OptionsResolver; |
|
14 | ||
15 | class DateFilter extends AbstractComparatorFilter |
|
16 | { |
|
17 | /** |
|
18 | * {@inheritdoc} |
|
19 | */ |
|
20 | public function buildForm(FormBuilderInterface $builder, array $options) |
|
21 | { |
|
22 | $builder->add('apply', CheckboxType::class, []); |
|
23 | $this->addComparatorChoice($builder, $options); |
|
24 | $builder->add('value', DateType::class, []); |
|
25 | } |
|
26 | ||
27 | /** |
|
28 | * {@inheritdoc} |
|
29 | */ |
|
30 | public function getExpression(string $fieldName, array $data): Expression |
|
31 | { |
|
32 | $comparator = $data['comparator'] ?: Comparison::EQUALS; |
|
33 | ||
34 | return Query::comparison( |
|
35 | $comparator, |
|
36 | $fieldName, |
|
37 | $data['value'] |
|
38 | ); |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * {@inheritdoc} |
|
43 | */ |
|
44 | public function isApplicable(array $filterData): bool |
|
45 | { |
|
46 | return (bool) $filterData['apply']; |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * {@inheritdoc} |
|
51 | */ |
|
52 | public function configureOptions(OptionsResolver $options) |
|
53 | { |
|
54 | $options->setDefault('comparators', $this->getComparatorMap()); |
|
55 | } |
|
56 | ||
57 | protected function getComparatorMap(): array |
|
58 | { |
|
59 | $supported = [ |
|
60 | Comparison::EQUALS, |
|
61 | Comparison::NOT_EQUALS, |
|
62 | Comparison::GREATER_THAN, |
|
63 | Comparison::GREATER_THAN_EQUAL, |
|
64 | Comparison::LESS_THAN_EQUAL, |
|
65 | Comparison::LESS_THAN, |
|
66 | ]; |
|
67 | ||
68 | return array_combine($supported, $supported); |
|
69 | } |
|
70 | } |
|
71 |
@@ 14-71 (lines=58) @@ | ||
11 | use Symfony\Component\Form\FormBuilderInterface; |
|
12 | use Symfony\Component\OptionsResolver\OptionsResolver; |
|
13 | ||
14 | class NumberFilter extends AbstractComparatorFilter |
|
15 | { |
|
16 | /** |
|
17 | * {@inheritdoc} |
|
18 | */ |
|
19 | public function buildForm(FormBuilderInterface $builder, array $options) |
|
20 | { |
|
21 | $this->addComparatorChoice($builder, $options); |
|
22 | ||
23 | $builder->add('value', NumberType::class, [ |
|
24 | 'required' => false, |
|
25 | ]); |
|
26 | } |
|
27 | ||
28 | /** |
|
29 | * {@inheritdoc} |
|
30 | */ |
|
31 | public function getExpression(string $fieldName, array $data): Expression |
|
32 | { |
|
33 | $comparator = $data['comparator'] ?: Comparison::EQUALS; |
|
34 | ||
35 | return Query::comparison( |
|
36 | $comparator, |
|
37 | $fieldName, |
|
38 | $data['value'] |
|
39 | ); |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * {@inheritdoc} |
|
44 | */ |
|
45 | public function configureOptions(OptionsResolver $options) |
|
46 | { |
|
47 | $options->setDefault('comparators', $this->getComparatorMap()); |
|
48 | } |
|
49 | ||
50 | /** |
|
51 | * {@inheritdoc} |
|
52 | */ |
|
53 | public function isApplicable(array $filterData): bool |
|
54 | { |
|
55 | return isset($filterData['value']); |
|
56 | } |
|
57 | ||
58 | protected function getComparatorMap(): array |
|
59 | { |
|
60 | $supported = [ |
|
61 | Comparison::EQUALS, |
|
62 | Comparison::NOT_EQUALS, |
|
63 | Comparison::GREATER_THAN, |
|
64 | Comparison::GREATER_THAN_EQUAL, |
|
65 | Comparison::LESS_THAN_EQUAL, |
|
66 | Comparison::LESS_THAN, |
|
67 | ]; |
|
68 | ||
69 | return array_combine($supported, $supported); |
|
70 | } |
|
71 | } |
|
72 |