|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Filter; |
|
15
|
|
|
|
|
16
|
|
|
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; |
|
17
|
|
|
use Sonata\AdminBundle\Form\Type\Filter\DefaultType; |
|
18
|
|
|
use Sonata\Form\Type\BooleanType; |
|
19
|
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
|
20
|
|
|
|
|
21
|
|
|
final class EmptyFilter 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_YES === (int) $data['value']) { |
|
35
|
|
|
$this->applyWhere( |
|
36
|
|
|
$queryBuilder, |
|
37
|
|
|
$queryBuilder |
|
38
|
|
|
->expr() |
|
39
|
|
|
->isNull(sprintf('%s.%s', $alias, $field)) |
|
40
|
|
|
); |
|
41
|
|
|
} elseif (BooleanType::TYPE_NO === (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
|
|
|
|