1 | <?php |
||
32 | abstract class Filter extends \Grido\Components\Component |
||
33 | 1 | { |
|
34 | 1 | const ID = 'filters'; |
|
35 | 1 | ||
36 | const VALUE_IDENTIFIER = '%value'; |
||
37 | |||
38 | const RENDER_INNER = 'inner'; |
||
39 | const RENDER_OUTER = 'outer'; |
||
40 | |||
41 | /** @var mixed */ |
||
42 | protected $optional; |
||
43 | |||
44 | /** @var array */ |
||
45 | protected $column = []; |
||
46 | |||
47 | /** @var string */ |
||
48 | protected $condition = '= ?'; |
||
49 | |||
50 | /** @var callable */ |
||
51 | protected $where; |
||
52 | |||
53 | /** @var string */ |
||
54 | protected $formatValue; |
||
55 | |||
56 | /** @var \Nette\Utils\Html */ |
||
57 | protected $wrapperPrototype; |
||
58 | |||
59 | /** @var \Nette\Forms\Controls\BaseControl */ |
||
60 | protected $control; |
||
61 | |||
62 | /** |
||
63 | * @param \Grido\Grid $grid |
||
64 | * @param string $name |
||
65 | * @param string $label |
||
66 | */ |
||
67 | public function __construct($grid, $name, $label) |
||
83 | |||
84 | /**********************************************************************************************/ |
||
85 | |||
86 | /** |
||
87 | * Map to database column. |
||
88 | * @param string $column |
||
89 | * @param string $operator |
||
90 | * @return Filter |
||
91 | * @throws Exception |
||
92 | */ |
||
93 | 1 | public function setColumn($column, $operator = Condition::OPERATOR_OR) |
|
110 | |||
111 | /** |
||
112 | * Sets custom condition. |
||
113 | * @param $condition |
||
114 | * @return Filter |
||
115 | */ |
||
116 | public function setCondition($condition) |
||
121 | |||
122 | /** |
||
123 | * Sets custom "sql" where. |
||
124 | * @param callable $callback function($value, $source) {} |
||
125 | * @return Filter |
||
126 | */ |
||
127 | public function setWhere($callback) |
||
132 | |||
133 | /** |
||
134 | * Sets custom format value. |
||
135 | * @param string $format for example: "%%value%" |
||
136 | * @return Filter |
||
137 | */ |
||
138 | public function setFormatValue($format) |
||
143 | |||
144 | /** |
||
145 | * Sets default value. |
||
146 | * @param string $value |
||
147 | * @return Filter |
||
148 | */ |
||
149 | public function setDefaultValue($value) |
||
154 | |||
155 | /**********************************************************************************************/ |
||
156 | |||
157 | /** |
||
158 | * @return array |
||
159 | * @internal |
||
160 | */ |
||
161 | public function getColumn() |
||
174 | |||
175 | /** |
||
176 | * @return \Nette\Forms\Controls\BaseControl |
||
177 | * @internal |
||
178 | */ |
||
179 | public function getControl() |
||
187 | |||
188 | /** |
||
189 | * @throws Exception |
||
190 | */ |
||
191 | protected function getFormControl() |
||
195 | |||
196 | /** |
||
197 | * Returns wrapper prototype (<th> html tag). |
||
198 | * @return \Nette\Utils\Html |
||
199 | */ |
||
200 | public function getWrapperPrototype() |
||
209 | |||
210 | /** |
||
211 | * @return string |
||
212 | */ |
||
213 | public function getCondition() |
||
217 | |||
218 | /** |
||
219 | * @param mixed $value |
||
220 | * @return Condition|bool |
||
221 | * @throws Exception |
||
222 | * @internal |
||
223 | */ |
||
224 | public function __getCondition($value) |
||
257 | |||
258 | /**********************************************************************************************/ |
||
259 | |||
260 | /** |
||
261 | * Format value for database. |
||
262 | * @param string $value |
||
263 | * @return string |
||
264 | */ |
||
265 | protected function formatValue($value) |
||
273 | |||
274 | /** |
||
275 | * Value representation in URI. |
||
276 | * @param string $value |
||
277 | * @return string |
||
278 | * @internal |
||
279 | */ |
||
280 | public function changeValue($value) |
||
284 | } |
||
285 |