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 | |||
49 | /** |
||
50 | * HTML Attributes to add to cells |
||
51 | * [attributeName => value] |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $cell_html_attributes = []; |
||
55 | |||
56 | /** |
||
57 | * Constructor. |
||
58 | * |
||
59 | * @param string|null $name column unique name for internal usage |
||
60 | * @param string|null $label column label |
||
61 | */ |
||
62 | public function __construct($name = null, $label = null) |
||
71 | |||
72 | /** |
||
73 | * Returns column order. |
||
74 | * |
||
75 | * This property used to to identify column position in grid. |
||
76 | * |
||
77 | * @return int |
||
78 | */ |
||
79 | public function getOrder() |
||
83 | |||
84 | /** |
||
85 | * Sets column order. |
||
86 | * |
||
87 | * This property used to to identify column position in grid. |
||
88 | * |
||
89 | * @param $order |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function setOrder($order) |
||
97 | |||
98 | /** |
||
99 | * Returns field name. |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | public function getName() |
||
107 | |||
108 | /** |
||
109 | * Sets field name. |
||
110 | * |
||
111 | * @param string $name |
||
112 | * @return $this |
||
113 | */ |
||
114 | public function setName($name) |
||
119 | |||
120 | /** |
||
121 | * Returns true if column is hidden. |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | public function isHidden() |
||
129 | |||
130 | /** |
||
131 | * Makes column hidden. |
||
132 | * |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function hide() |
||
140 | |||
141 | /** |
||
142 | * Makes column visible. |
||
143 | * |
||
144 | * @return $this |
||
145 | */ |
||
146 | public function show() |
||
151 | |||
152 | /** |
||
153 | * Returns text label that will be rendered in table header. |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | public function getLabel() |
||
161 | |||
162 | /** |
||
163 | * Sets text label that will be rendered in table header. |
||
164 | * |
||
165 | * @param string $label |
||
166 | * @return $this |
||
167 | */ |
||
168 | public function setLabel($label) |
||
173 | |||
174 | /** |
||
175 | * Returns true if column is sortable (sorting controls must be rendered). |
||
176 | * |
||
177 | * @return bool |
||
178 | */ |
||
179 | public function isSortable() |
||
183 | |||
184 | /** |
||
185 | * Allows to enable or disable sorting controls for column. |
||
186 | * |
||
187 | * @param boolean $isSortable |
||
188 | * @return $this |
||
189 | */ |
||
190 | public function setSortable($isSortable) |
||
195 | |||
196 | /** |
||
197 | * Returns current sorting order |
||
198 | * or null if table rows are not sorted using this column. |
||
199 | * |
||
200 | * @return null|string null|Grid::SORT_ASC|Grid::SORT_DESC |
||
201 | */ |
||
202 | public function getSorting() |
||
206 | |||
207 | /** |
||
208 | * Allows to specify sorting by this column for data rows. |
||
209 | * |
||
210 | * @param null|string $sortOrder null|Grid::SORT_ASC|Grid::SORT_DESC |
||
211 | * @return $this |
||
212 | */ |
||
213 | public function setSorting($sortOrder) |
||
218 | |||
219 | /** |
||
220 | * Returns true if data rows are sorted ascending using this column. |
||
221 | * |
||
222 | * @return bool |
||
223 | */ |
||
224 | public function isSortedAsc() |
||
228 | |||
229 | /** |
||
230 | * Returns true if data rows are sorted descending using this column. |
||
231 | * |
||
232 | * @return bool |
||
233 | */ |
||
234 | public function isSortedDesc() |
||
238 | |||
239 | /** |
||
240 | * Allows to set callback function that will render |
||
241 | * content of table cells for this column. |
||
242 | * |
||
243 | * @param callable $callback |
||
244 | * @return $this |
||
245 | */ |
||
246 | public function setCallback($callback) |
||
251 | |||
252 | /** |
||
253 | * Returns function that will render |
||
254 | * content of table cells for this column if specified. |
||
255 | * |
||
256 | * @return callable|null |
||
257 | */ |
||
258 | public function getCallback() |
||
262 | |||
263 | /** |
||
264 | * Allows to specify filtering controls for column. |
||
265 | * |
||
266 | * @param Collection|FilterConfig[] $filters |
||
267 | * @return $this |
||
268 | */ |
||
269 | public function setFilters($filters) |
||
278 | |||
279 | /** |
||
280 | * Allows to add filtering control to column. |
||
281 | * |
||
282 | * @param FilterConfig $filter |
||
283 | * @return $this |
||
284 | */ |
||
285 | public function addFilter(FilterConfig $filter) |
||
291 | |||
292 | /** |
||
293 | * Creates instance of filtering control configuration |
||
294 | * and binds it to the column. |
||
295 | * |
||
296 | * @param string $class |
||
297 | * @return FilterConfig |
||
298 | */ |
||
299 | public function makeFilter($class = '\Nayjest\Grids\FilterConfig') |
||
305 | |||
306 | /** |
||
307 | * Returns true if any filtering controls specified for the column. |
||
308 | * |
||
309 | * @return bool |
||
310 | */ |
||
311 | public function hasFilters() |
||
315 | |||
316 | /** |
||
317 | * Returns list of filtering controls specified for the column. |
||
318 | * |
||
319 | * @return Collection|FilterConfig[] |
||
320 | */ |
||
321 | public function getFilters() |
||
328 | |||
329 | /** |
||
330 | * @todo move to Field instance |
||
331 | * @param DataRowInterface $row |
||
332 | * @return mixed |
||
333 | */ |
||
334 | public function getValue(DataRowInterface $row) |
||
342 | |||
343 | /** |
||
344 | * @return array |
||
345 | */ |
||
346 | public function getCellHtmlAttributes() |
||
350 | |||
351 | /** |
||
352 | * @param array $cell_html_attributes |
||
353 | */ |
||
354 | public function setCellHtmlAttributes($cell_html_attributes) |
||
359 | } |
||
360 |