1 | <?php |
||
21 | class BooleanFilter extends Filter |
||
22 | { |
||
23 | /** |
||
24 | * @param string $alias |
||
25 | * @param string $field |
||
26 | * @param mixed $data |
||
27 | */ |
||
28 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data): void |
||
29 | { |
||
30 | if (!$data || !\is_array($data) || !\array_key_exists('type', $data) || !\array_key_exists('value', $data)) { |
||
31 | return; |
||
32 | } |
||
33 | |||
34 | if (\is_array($data['value'])) { |
||
35 | $values = []; |
||
36 | foreach ($data['value'] as $v) { |
||
37 | if (!\in_array($v, [BooleanType::TYPE_NO, BooleanType::TYPE_YES], true)) { |
||
38 | continue; |
||
39 | } |
||
40 | |||
41 | $values[] = BooleanType::TYPE_YES === $v; |
||
42 | } |
||
43 | |||
44 | if (0 === \count($values)) { |
||
45 | return; |
||
46 | } |
||
47 | |||
48 | $queryBuilder->field($field)->in($values); |
||
49 | $this->active = true; |
||
50 | } else { |
||
51 | if (!\in_array($data['value'], [BooleanType::TYPE_NO, BooleanType::TYPE_YES], true)) { |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | $value = BooleanType::TYPE_YES === $data['value']; |
||
56 | |||
57 | $queryBuilder->field($field)->equals($value); |
||
58 | $this->active = true; |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @return array |
||
64 | */ |
||
65 | public function getDefaultOptions() |
||
69 | |||
70 | public function getRenderSettings() |
||
80 | } |
||
81 |