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