1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Psi\Component\Grid\Filter; |
6
|
|
|
|
7
|
|
|
use Psi\Component\ObjectAgent\Capabilities; |
8
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
9
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
10
|
|
|
use Symfony\Component\Form\Extension\Core\Type\FormType; |
11
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
12
|
|
|
use Psi\Component\Grid\Metadata\GridMetadata; |
13
|
|
|
use Psi\Component\ObjectAgent\Query\Comparison; |
14
|
|
|
use Psi\Component\ObjectAgent\Query\Query; |
15
|
|
|
use Psi\Component\Grid\FilterInterface; |
16
|
|
|
use Psi\Component\ObjectAgent\Query\Expression; |
17
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
18
|
|
|
use Symfony\Component\Form\FormInterface; |
19
|
|
|
use Symfony\Component\Form\AbstractType; |
20
|
|
|
use Symfony\Component\Validator\Constraints\NotNull; |
21
|
|
|
use Psi\Component\Grid\FilterDataInterface; |
22
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
23
|
|
|
|
24
|
|
|
class BooleanFilter implements FilterInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
30
|
|
|
{ |
31
|
|
|
$builder->add('checkbox', CheckboxType::class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function getExpression(string $fieldName, FilterDataInterface $data): Expression |
38
|
|
|
{ |
39
|
|
|
return Query::comparison( |
40
|
|
|
Comparison::EQUALS, |
41
|
|
|
$fieldName, |
42
|
|
|
$data->getValue() |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function configureOptions(OptionsResolver $options) |
50
|
|
|
{ |
51
|
|
|
$options->setDefault('data_class', StringFilterData::class); |
52
|
|
|
$options->setDefault('empty_data', function (FormInterface $form) { |
53
|
|
|
return new BooleanFilterData( |
54
|
|
|
$form->get('value')->getData() |
55
|
|
|
); |
56
|
|
|
}); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|