1 | <?php |
||
21 | final class EmptyFieldFilter extends Filter |
||
22 | { |
||
23 | /** |
||
24 | * @param string $alias |
||
25 | * @param string $field |
||
26 | * @param mixed[]|null $data |
||
27 | */ |
||
28 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data): void |
||
29 | { |
||
30 | if (null === $data || !\is_array($data) || !\array_key_exists('value', $data)) { |
||
31 | return; |
||
32 | } |
||
33 | |||
34 | if (BooleanType::TYPE_NO === (int) $data['value']) { |
||
35 | $this->applyWhere( |
||
36 | $queryBuilder, |
||
37 | $queryBuilder |
||
38 | ->expr() |
||
39 | ->isNull(sprintf('%s.%s', $alias, $field)) |
||
40 | ); |
||
41 | } elseif (BooleanType::TYPE_YES === (int) $data['value']) { |
||
42 | $this->applyWhere( |
||
43 | $queryBuilder, |
||
44 | $queryBuilder |
||
45 | ->expr() |
||
46 | ->isNotNull(sprintf('%s.%s', $alias, $field)) |
||
47 | ); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | public function getDefaultOptions() |
||
52 | { |
||
53 | return [ |
||
54 | 'field_type' => BooleanType::class, |
||
55 | 'operator_type' => HiddenType::class, |
||
56 | 'operator_options' => [], |
||
57 | ]; |
||
58 | } |
||
59 | |||
60 | public function getRenderSettings() |
||
61 | { |
||
62 | return [DefaultType::class, [ |
||
63 | 'field_type' => $this->getFieldType(), |
||
64 | 'field_options' => $this->getFieldOptions(), |
||
65 | 'operator_type' => $this->getOption('operator_type'), |
||
66 | 'operator_options' => $this->getOption('operator_options'), |
||
67 | 'label' => $this->getLabel(), |
||
68 | ]]; |
||
69 | } |
||
70 | |||
71 | public function getParentAssociationMappings() |
||
72 | { |
||
73 | $mappings = $this->getOption('parent_association_mappings', []); |
||
74 | |||
75 | $fields = explode('.', $this->getFieldName()); |
||
76 | for ($i = 0; $i < \count($fields) - 1; ++$i) { |
||
77 | $mappings[] = ['fieldName' => $fields[$i]]; |
||
78 | } |
||
79 | |||
80 | return $mappings; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param mixed|null $data |
||
85 | * |
||
86 | * @return string[] |
||
87 | */ |
||
88 | protected function association(ProxyQueryInterface $queryBuilder, $data): array |
||
96 | } |
||
97 |