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 | * Constructor. |
||
51 | * |
||
52 | * @param string|null $name column unique name for internal usage |
||
53 | * @param string|null $label column label |
||
54 | */ |
||
55 | public function __construct($name = null, $label = null) |
||
56 | { |
||
57 | if ($name !== null) { |
||
58 | $this->setName($name); |
||
59 | } |
||
60 | if ($label !== null) { |
||
61 | $this->setLabel($label); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Returns column order. |
||
67 | * |
||
68 | * This property used to to identify column position in grid. |
||
69 | * |
||
70 | * @return int |
||
71 | */ |
||
72 | public function getOrder() |
||
73 | { |
||
74 | return $this->order; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Sets column order. |
||
79 | * |
||
80 | * This property used to to identify column position in grid. |
||
81 | * |
||
82 | * @param $order |
||
83 | * @return $this |
||
84 | */ |
||
85 | public function setOrder($order) |
||
86 | { |
||
87 | $this->order = $order; |
||
88 | return $this; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Returns field name. |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getName() |
||
97 | { |
||
98 | return $this->name; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Sets field name. |
||
103 | * |
||
104 | * @param string $name |
||
105 | * @return $this |
||
106 | */ |
||
107 | public function setName($name) |
||
108 | { |
||
109 | $this->name = $name; |
||
110 | return $this; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Returns true if column is hidden. |
||
115 | * |
||
116 | * @return bool |
||
117 | */ |
||
118 | public function isHidden() |
||
119 | { |
||
120 | return $this->is_hidden; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Makes column hidden. |
||
125 | * |
||
126 | * @return $this |
||
127 | */ |
||
128 | public function hide() |
||
129 | { |
||
130 | $this->is_hidden = true; |
||
131 | return $this; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Makes column visible. |
||
136 | * |
||
137 | * @return $this |
||
138 | */ |
||
139 | public function show() |
||
140 | { |
||
141 | $this->is_hidden = false; |
||
142 | return $this; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Returns text label that will be rendered in table header. |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | public function getLabel() |
||
151 | { |
||
152 | return $this->label ? : ucwords(str_replace(array('-', '_', '.'), ' ', $this->name)); |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Sets text label that will be rendered in table header. |
||
157 | * |
||
158 | * @param string $label |
||
159 | * @return $this |
||
160 | */ |
||
161 | public function setLabel($label) |
||
162 | { |
||
163 | $this->label = $label; |
||
164 | return $this; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * Returns true if column is sortable (sorting controls must be rendered). |
||
169 | * |
||
170 | * @return bool |
||
171 | */ |
||
172 | public function isSortable() |
||
173 | { |
||
174 | return $this->is_sortable; |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * Allows to enable or disable sorting controls for column. |
||
179 | * |
||
180 | * @param boolean $isSortable |
||
181 | * @return $this |
||
182 | */ |
||
183 | public function setSortable($isSortable) |
||
188 | |||
189 | /** |
||
190 | * Returns current sorting order |
||
191 | * or null if table rows are not sorted using this column. |
||
192 | * |
||
193 | * @return null|string null|Grid::SORT_ASC|Grid::SORT_DESC |
||
194 | */ |
||
195 | public function getSorting() |
||
196 | { |
||
197 | return $this->sorting; |
||
199 | |||
200 | /** |
||
201 | * Allows to specify sorting by this column for data rows. |
||
202 | * |
||
203 | * @param null|string $sortOrder null|Grid::SORT_ASC|Grid::SORT_DESC |
||
204 | * @return $this |
||
205 | */ |
||
206 | public function setSorting($sortOrder) |
||
207 | { |
||
208 | $this->sorting = $sortOrder; |
||
209 | return $this; |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * Returns true if data rows are sorted ascending using this column. |
||
214 | * |
||
215 | * @return bool |
||
216 | */ |
||
217 | public function isSortedAsc() |
||
221 | |||
222 | /** |
||
223 | * Returns true if data rows are sorted descending using this column. |
||
224 | * |
||
225 | * @return bool |
||
226 | */ |
||
227 | public function isSortedDesc() |
||
231 | |||
232 | /** |
||
233 | * Allows to set callback function that will render |
||
234 | * content of table cells for this column. |
||
235 | * |
||
236 | * @param callable $callback |
||
237 | * @return $this |
||
238 | */ |
||
239 | public function setCallback($callback) |
||
244 | |||
245 | /** |
||
246 | * Returns function that will render |
||
247 | * content of table cells for this column if specified. |
||
248 | * |
||
249 | * @return callable|null |
||
250 | */ |
||
251 | public function getCallback() |
||
255 | |||
256 | /** |
||
257 | * Allows to specify filtering controls for column. |
||
258 | * |
||
259 | * @param Collection|FilterConfig[] $filters |
||
260 | * @return $this |
||
261 | */ |
||
262 | public function setFilters($filters) |
||
271 | |||
272 | /** |
||
273 | * Allows to add filtering control to column. |
||
274 | * |
||
275 | * @param FilterConfig $filter |
||
276 | * @return $this |
||
277 | */ |
||
278 | public function addFilter(FilterConfig $filter) |
||
284 | |||
285 | /** |
||
286 | * Creates instance of filtering control configuration |
||
287 | * and binds it to the column. |
||
288 | * |
||
289 | * @param string $class |
||
290 | * @return FilterConfig |
||
291 | */ |
||
292 | public function makeFilter($class = '\Nayjest\Grids\FilterConfig') |
||
298 | |||
299 | /** |
||
300 | * Returns true if any filtering controls specified for the column. |
||
301 | * |
||
302 | * @return bool |
||
303 | */ |
||
304 | public function hasFilters() |
||
308 | |||
309 | /** |
||
310 | * Returns list of filtering controls specified for the column. |
||
311 | * |
||
312 | * @return Collection|FilterConfig[] |
||
313 | */ |
||
314 | public function getFilters() |
||
321 | |||
322 | /** |
||
323 | * @todo move to Field instance |
||
324 | * @param DataRowInterface $row |
||
325 | * @return mixed |
||
326 | */ |
||
327 | public function getValue(DataRowInterface $row) |
||
335 | |||
336 | public function addStyleAttribute($name, $value){ |
||
337 | $this->styleAttributes = $this->styleAttributes. $name. ':' . $value . ';'; |
||
|
|||
338 | return $this; |
||
340 | |||
341 | public function getStyleAttributes(){ |
||
344 | |||
345 | public function setFormat($format){ |
||
348 | |||
349 | public function getFormat(){ |
||
352 | } |
||
353 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: