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 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $attributes = []; |
||
51 | |||
52 | protected $is_hidden = false; |
||
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) |
||
61 | { |
||
62 | if ($name !== null) { |
||
63 | $this->setName($name); |
||
64 | } |
||
65 | if ($label !== null) { |
||
66 | $this->setLabel($label); |
||
67 | } |
||
68 | } |
||
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 | * Makes column hidden. |
||
130 | * |
||
131 | * @return $this |
||
132 | */ |
||
133 | public function hide() |
||
138 | |||
139 | /** |
||
140 | * Makes column visible. |
||
141 | * |
||
142 | * @return $this |
||
143 | */ |
||
144 | public function show() |
||
149 | |||
150 | /** |
||
151 | * Returns text label that will be rendered in table header. |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getLabel() |
||
159 | |||
160 | /** |
||
161 | * Sets text label that will be rendered in table header. |
||
162 | * |
||
163 | * @param string $label |
||
164 | * @return $this |
||
165 | */ |
||
166 | public function setLabel($label) |
||
171 | |||
172 | /** |
||
173 | * Returns true if column is sortable (sorting controls must be rendered). |
||
174 | * |
||
175 | * @return bool |
||
176 | */ |
||
177 | public function isSortable() |
||
181 | |||
182 | /** |
||
183 | * Allows to enable or disable sorting controls for column. |
||
184 | * |
||
185 | * @param boolean $isSortable |
||
186 | * @return $this |
||
187 | */ |
||
188 | public function setSortable($isSortable) |
||
193 | |||
194 | /** |
||
195 | * Returns current sorting order |
||
196 | * or null if table rows are not sorted using this column. |
||
197 | * |
||
198 | * @return null|string null|Grid::SORT_ASC|Grid::SORT_DESC |
||
199 | */ |
||
200 | public function getSorting() |
||
204 | |||
205 | /** |
||
206 | * Allows to specify sorting by this column for data rows. |
||
207 | * |
||
208 | * @param null|string $sortOrder null|Grid::SORT_ASC|Grid::SORT_DESC |
||
209 | * @return $this |
||
210 | */ |
||
211 | public function setSorting($sortOrder) |
||
216 | |||
217 | /** |
||
218 | * Returns true if data rows are sorted ascending using this column. |
||
219 | * |
||
220 | * @return bool |
||
221 | */ |
||
222 | public function isSortedAsc() |
||
226 | |||
227 | /** |
||
228 | * Returns true if data rows are sorted descending using this column. |
||
229 | * |
||
230 | * @return bool |
||
231 | */ |
||
232 | public function isSortedDesc() |
||
236 | |||
237 | /** |
||
238 | * Allows to set callback function that will render |
||
239 | * content of table cells for this column. |
||
240 | * |
||
241 | * @param callable $callback |
||
242 | * @return $this |
||
243 | */ |
||
244 | public function setCallback($callback) |
||
249 | |||
250 | /** |
||
251 | * Returns function that will render |
||
252 | * content of table cells for this column if specified. |
||
253 | * |
||
254 | * @return callable|null |
||
255 | */ |
||
256 | public function getCallback() |
||
260 | |||
261 | /** |
||
262 | * Allows to specify filtering controls for column. |
||
263 | * |
||
264 | * @param Collection|FilterConfig[] $filters |
||
265 | * @return $this |
||
266 | */ |
||
267 | public function setFilters($filters) |
||
276 | |||
277 | /** |
||
278 | * Allows to add filtering control to column. |
||
279 | * |
||
280 | * @param FilterConfig $filter |
||
281 | * @return $this |
||
282 | */ |
||
283 | public function addFilter(FilterConfig $filter) |
||
289 | |||
290 | /** |
||
291 | * Creates instance of filtering control configuration |
||
292 | * and binds it to the column. |
||
293 | * |
||
294 | * @param string $class |
||
295 | * @return FilterConfig |
||
296 | */ |
||
297 | public function makeFilter($class = '\Nayjest\Grids\FilterConfig') |
||
303 | |||
304 | /** |
||
305 | * Returns true if any filtering controls specified for the column. |
||
306 | * |
||
307 | * @return bool |
||
308 | */ |
||
309 | public function hasFilters() |
||
313 | |||
314 | /** |
||
315 | * Returns list of filtering controls specified for the column. |
||
316 | * |
||
317 | * @return Collection|FilterConfig[] |
||
318 | */ |
||
319 | public function getFilters() |
||
326 | |||
327 | /** |
||
328 | * @todo move to Field instance |
||
329 | * @param DataRowInterface $row |
||
330 | * @return mixed |
||
331 | */ |
||
332 | public function getValue(DataRowInterface $row) |
||
340 | |||
341 | /** |
||
342 | * @param array $attributes |
||
343 | * @return $this |
||
344 | */ |
||
345 | public function setAttributes($attributes) |
||
350 | |||
351 | /** |
||
352 | * @return array |
||
353 | */ |
||
354 | public function getAttributes() |
||
358 | } |
||
359 |