1 | <?php |
||
18 | class ActiveDataFilter extends DataFilter |
||
19 | { |
||
20 | /** |
||
21 | * @var array maps filtering condition keywords to build methods. |
||
22 | * These methods are used by [[buildCondition()]] to build the actual filtering conditions. |
||
23 | * Particular condition builder can be specified using a PHP callback. For example: |
||
24 | * |
||
25 | * ```php |
||
26 | * [ |
||
27 | * 'XOR' => function (string $operator, mixed $condition) { |
||
28 | * //return array; |
||
29 | * }, |
||
30 | * 'LIKE' => function (string $operator, mixed $condition, string $attribute) { |
||
31 | * //return array; |
||
32 | * }, |
||
33 | * ] |
||
34 | * ``` |
||
35 | */ |
||
36 | public $conditionBuilders = [ |
||
37 | 'AND' => 'buildConjunctionCondition', |
||
38 | 'OR' => 'buildConjunctionCondition', |
||
39 | 'NOT' => 'buildBlockCondition', |
||
40 | '<' => 'buildOperatorCondition', |
||
41 | '>' => 'buildOperatorCondition', |
||
42 | '<=' => 'buildOperatorCondition', |
||
43 | '>=' => 'buildOperatorCondition', |
||
44 | '=' => 'buildOperatorCondition', |
||
45 | '!=' => 'buildOperatorCondition', |
||
46 | 'IN' => 'buildOperatorCondition', |
||
47 | 'NOT IN' => 'buildOperatorCondition', |
||
48 | 'LIKE' => 'buildOperatorCondition', |
||
49 | ]; |
||
50 | /** |
||
51 | * @var array map filtering operators to operators used in [[\yii\db\QueryInterface::where()]]. |
||
52 | * The format is: `[filterOperator => queryOperator]`. |
||
53 | * If particular operator keyword does not appear in the map, it will be used as is. |
||
54 | * |
||
55 | * Usually the map can be left empty as filter operator names are consistent with the ones |
||
56 | * used in [[\yii\db\QueryInterface::where()]]. However, you may want to adjust it in some special cases. |
||
57 | * For example, when using PosgreSQL you may want to setup the following map: |
||
58 | * |
||
59 | * ```php |
||
60 | * [ |
||
61 | * 'LIKE' => 'ILIKE' |
||
62 | * ] |
||
63 | * ``` |
||
64 | */ |
||
65 | public $queryOperatorMap = []; |
||
66 | |||
67 | |||
68 | /** |
||
69 | * @inheritdoc |
||
70 | */ |
||
71 | 8 | protected function buildInternal() |
|
80 | |||
81 | /** |
||
82 | * @param array $condition |
||
83 | * @return array built condition. |
||
84 | */ |
||
85 | 7 | protected function buildCondition($condition) |
|
112 | |||
113 | /** |
||
114 | * Builds conjunction condition, which consists of multiple independent ones. |
||
115 | * It covers such operators as `and` and `or`. |
||
116 | * @param string $operator operator keyword. |
||
117 | * @param mixed $condition raw condition. |
||
118 | * @return array actual condition. |
||
119 | */ |
||
120 | 2 | protected function buildConjunctionCondition($operator, $condition) |
|
133 | |||
134 | /** |
||
135 | * Builds block condition, which consists of a single condition. |
||
136 | * It covers such operators as `not`. |
||
137 | * @param string $operator operator keyword. |
||
138 | * @param mixed $condition raw condition. |
||
139 | * @return array actual condition. |
||
140 | */ |
||
141 | 1 | protected function buildBlockCondition($operator, $condition) |
|
151 | |||
152 | /** |
||
153 | * Builds search condition for a particular attribute. |
||
154 | * @param string $attribute search attribute name. |
||
155 | * @param mixed $condition search condition. |
||
156 | * @return array actual condition. |
||
157 | */ |
||
158 | 7 | protected function buildAttributeCondition($attribute, $condition) |
|
188 | |||
189 | /** |
||
190 | * Builds an operator condition. |
||
191 | * @param string $operator operator keyword. |
||
192 | * @param mixed $condition attribute condition. |
||
193 | * @param string $attribute attribute name. |
||
194 | * @return array actual condition. |
||
195 | */ |
||
196 | 2 | protected function buildOperatorCondition($operator, $condition, $attribute) |
|
203 | } |
||
204 |