1 | <?php |
||
13 | class FieldConfig |
||
14 | { |
||
15 | /** |
||
16 | * Field name. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $name; |
||
21 | |||
22 | /** |
||
23 | * Text label that will be rendered in table header. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $label; |
||
28 | |||
29 | /** |
||
30 | * @var int |
||
31 | */ |
||
32 | protected $order = 0; |
||
33 | |||
34 | /** |
||
35 | * @var bool |
||
36 | */ |
||
37 | protected $is_sortable = false; |
||
38 | |||
39 | protected $sorting; |
||
40 | |||
41 | /** @var Collection|FilterConfig[] */ |
||
42 | protected $filters; |
||
43 | |||
44 | /** @var callable */ |
||
45 | protected $callback; |
||
46 | |||
47 | protected $is_hidden = false; |
||
48 | protected $is_hiddenXs = false; |
||
49 | protected $is_hiddenSm = false; |
||
50 | protected $is_hiddenMd = false; |
||
51 | protected $is_hiddenLg = false; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * Constructor. |
||
56 | * |
||
57 | * @param string|null $name column unique name for internal usage |
||
58 | * @param string|null $label column label |
||
59 | */ |
||
60 | public function __construct($name = null, $label = null) |
||
69 | |||
70 | /** |
||
71 | * Returns column order. |
||
72 | * |
||
73 | * This property used to to identify column position in grid. |
||
74 | * |
||
75 | * @return int |
||
76 | */ |
||
77 | public function getOrder() |
||
81 | |||
82 | /** |
||
83 | * Sets column order. |
||
84 | * |
||
85 | * This property used to to identify column position in grid. |
||
86 | * |
||
87 | * @param $order |
||
88 | * @return $this |
||
89 | */ |
||
90 | public function setOrder($order) |
||
95 | |||
96 | /** |
||
97 | * Returns field name. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getName() |
||
105 | |||
106 | /** |
||
107 | * Sets field name. |
||
108 | * |
||
109 | * @param string $name |
||
110 | * @return $this |
||
111 | */ |
||
112 | public function setName($name) |
||
117 | |||
118 | /** |
||
119 | * Returns true if column is hidden. |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | public function isHidden() |
||
127 | |||
128 | /** |
||
129 | * Returns true if column is hidden on xs. |
||
130 | * |
||
131 | * @return bool |
||
132 | */ |
||
133 | public function isHiddenXs() |
||
137 | |||
138 | /** |
||
139 | * Returns true if column is hidden on sm. |
||
140 | * |
||
141 | * @return bool |
||
142 | */ |
||
143 | public function isHiddenSm() |
||
147 | |||
148 | /** |
||
149 | * Returns true if column is hidden on md. |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | public function isHiddenMd() |
||
157 | |||
158 | |||
159 | /** |
||
160 | * Returns true if column is hidden on lg. |
||
161 | * |
||
162 | * @return bool |
||
163 | */ |
||
164 | public function isHiddenLg() |
||
168 | |||
169 | /** |
||
170 | * Makes column hidden. |
||
171 | * |
||
172 | * @return $this |
||
173 | */ |
||
174 | public function hide() |
||
179 | |||
180 | /** |
||
181 | * Makes column hidden on xs screens. |
||
182 | * |
||
183 | * @return $this |
||
184 | */ |
||
185 | public function hideXs() |
||
190 | |||
191 | /** |
||
192 | * Makes column hidden on sm screens. |
||
193 | * |
||
194 | * @return $this |
||
195 | */ |
||
196 | public function hideSm() |
||
201 | |||
202 | /** |
||
203 | * Makes column hidden on md screens. |
||
204 | * |
||
205 | * @return $this |
||
206 | */ |
||
207 | public function hideMd() |
||
212 | |||
213 | /** |
||
214 | * Makes column hidden on lg screens. |
||
215 | * |
||
216 | * @return $this |
||
217 | */ |
||
218 | public function hideLg() |
||
223 | |||
224 | /** |
||
225 | * Makes column visible. |
||
226 | * |
||
227 | * @return $this |
||
228 | */ |
||
229 | public function show() |
||
234 | |||
235 | /** |
||
236 | * Returns text label that will be rendered in table header. |
||
237 | * |
||
238 | * @return string |
||
239 | */ |
||
240 | public function getLabel() |
||
244 | |||
245 | /** |
||
246 | * Sets text label that will be rendered in table header. |
||
247 | * |
||
248 | * @param string $label |
||
249 | * @return $this |
||
250 | */ |
||
251 | public function setLabel($label) |
||
256 | |||
257 | /** |
||
258 | * Returns true if column is sortable (sorting controls must be rendered). |
||
259 | * |
||
260 | * @return bool |
||
261 | */ |
||
262 | public function isSortable() |
||
266 | |||
267 | /** |
||
268 | * Allows to enable or disable sorting controls for column. |
||
269 | * |
||
270 | * @param boolean $isSortable |
||
271 | * @return $this |
||
272 | */ |
||
273 | public function setSortable($isSortable) |
||
278 | |||
279 | /** |
||
280 | * Returns current sorting order |
||
281 | * or null if table rows are not sorted using this column. |
||
282 | * |
||
283 | * @return null|string null|Grid::SORT_ASC|Grid::SORT_DESC |
||
284 | */ |
||
285 | public function getSorting() |
||
289 | |||
290 | /** |
||
291 | * Allows to specify sorting by this column for data rows. |
||
292 | * |
||
293 | * @param null|string $sortOrder null|Grid::SORT_ASC|Grid::SORT_DESC |
||
294 | * @return $this |
||
295 | */ |
||
296 | public function setSorting($sortOrder) |
||
301 | |||
302 | /** |
||
303 | * Returns true if data rows are sorted ascending using this column. |
||
304 | * |
||
305 | * @return bool |
||
306 | */ |
||
307 | public function isSortedAsc() |
||
311 | |||
312 | /** |
||
313 | * Returns true if data rows are sorted descending using this column. |
||
314 | * |
||
315 | * @return bool |
||
316 | */ |
||
317 | public function isSortedDesc() |
||
321 | |||
322 | /** |
||
323 | * Allows to set callback function that will render |
||
324 | * content of table cells for this column. |
||
325 | * |
||
326 | * @param callable $callback |
||
327 | * @return $this |
||
328 | */ |
||
329 | public function setCallback($callback) |
||
334 | |||
335 | /** |
||
336 | * Returns function that will render |
||
337 | * content of table cells for this column if specified. |
||
338 | * |
||
339 | * @return callable|null |
||
340 | */ |
||
341 | public function getCallback() |
||
345 | |||
346 | /** |
||
347 | * Allows to specify filtering controls for column. |
||
348 | * |
||
349 | * @param Collection|FilterConfig[] $filters |
||
350 | * @return $this |
||
351 | */ |
||
352 | public function setFilters($filters) |
||
361 | |||
362 | /** |
||
363 | * Allows to add filtering control to column. |
||
364 | * |
||
365 | * @param FilterConfig $filter |
||
366 | * @return $this |
||
367 | */ |
||
368 | public function addFilter(FilterConfig $filter) |
||
374 | |||
375 | /** |
||
376 | * Creates instance of filtering control configuration |
||
377 | * and binds it to the column. |
||
378 | * |
||
379 | * @param string $class |
||
380 | * @return FilterConfig |
||
381 | */ |
||
382 | public function makeFilter($class = '\Nayjest\Grids\FilterConfig') |
||
388 | |||
389 | /** |
||
390 | * Returns true if any filtering controls specified for the column. |
||
391 | * |
||
392 | * @return bool |
||
393 | */ |
||
394 | public function hasFilters() |
||
398 | |||
399 | /** |
||
400 | * Returns list of filtering controls specified for the column. |
||
401 | * |
||
402 | * @return Collection|FilterConfig[] |
||
403 | */ |
||
404 | public function getFilters() |
||
411 | |||
412 | /** |
||
413 | * @todo move to Field instance |
||
414 | * @param DataRowInterface $row |
||
415 | * @return mixed |
||
416 | */ |
||
417 | public function getValue(DataRowInterface $row) |
||
425 | } |
||
426 |