1 | <?php |
||
20 | class ModelFilter extends Filter |
||
21 | { |
||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data) |
||
26 | { |
||
27 | if (!$data || !is_array($data) || !array_key_exists('value', $data) || empty($data['value'])) { |
||
28 | return; |
||
29 | } |
||
30 | |||
31 | if ($data['value'] instanceof Collection) { |
||
32 | $data['value'] = $data['value']->toArray(); |
||
33 | } |
||
34 | |||
35 | if (!is_array($data['value'])) { |
||
36 | $data['value'] = array($data['value']); |
||
37 | } |
||
38 | |||
39 | $this->handleMultiple($queryBuilder, $alias, $data); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public function getDefaultOptions() |
||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | public function getRenderSettings() |
||
79 | |||
80 | /** |
||
81 | * For the record, the $alias value is provided by the association method (and the entity join method) |
||
82 | * so the field value is not used here. |
||
83 | * |
||
84 | * @param ProxyQueryInterface|QueryBuilder $queryBuilder |
||
85 | * @param string $alias |
||
86 | * @param mixed $data |
||
87 | * |
||
88 | * @return mixed |
||
89 | */ |
||
90 | protected function handleMultiple(ProxyQueryInterface $queryBuilder, $alias, $data) |
||
91 | { |
||
92 | if (count($data['value']) == 0) { |
||
93 | return; |
||
94 | } |
||
95 | |||
96 | $parameterName = $this->getNewParameterName($queryBuilder); |
||
97 | |||
98 | if (isset($data['type']) && $data['type'] == EqualType::TYPE_IS_NOT_EQUAL) { |
||
99 | $or = $queryBuilder->expr()->orX(); |
||
100 | |||
101 | $or->add($queryBuilder->expr()->notIn($alias, ':'.$parameterName)); |
||
102 | |||
103 | $or->add($queryBuilder->expr()->isNull( |
||
104 | sprintf('IDENTITY(%s.%s)', $this->getParentAlias($queryBuilder, $alias), $this->getFieldName()) |
||
105 | )); |
||
106 | |||
107 | $this->applyWhere($queryBuilder, $or); |
||
108 | } else { |
||
109 | $this->applyWhere($queryBuilder, $queryBuilder->expr()->in($alias, ':'.$parameterName)); |
||
110 | } |
||
111 | |||
112 | $queryBuilder->setParameter($parameterName, $data['value']); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | protected function association(ProxyQueryInterface $queryBuilder, $data) |
||
137 | |||
138 | /** |
||
139 | * Retrieve the parent alias for given alias. |
||
140 | * Root alias for direct association or entity joined alias for association depth >= 2. |
||
141 | * |
||
142 | * @param ProxyQueryInterface $queryBuilder |
||
143 | * @param $alias |
||
144 | * |
||
145 | * @return mixed |
||
146 | */ |
||
147 | private function getParentAlias(ProxyQueryInterface $queryBuilder, $alias) |
||
163 | } |
||
164 |