|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace UniMan\Core; |
|
4
|
|
|
|
|
5
|
|
|
use UniMan\Core\Utils\Filter; |
|
6
|
|
|
use Closure; |
|
7
|
|
|
|
|
8
|
|
|
class Column |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* key in item result array |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
private $key; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* title (string is translated in template) |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $title; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* result can be orderer by this column |
|
24
|
|
|
* @var boolean |
|
25
|
|
|
*/ |
|
26
|
|
|
private $isSortable = false; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* result can be filtered by this column |
|
30
|
|
|
* @var boolean |
|
31
|
|
|
*/ |
|
32
|
|
|
private $isFilterable = false; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* list of filters for column |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
private $filters = []; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* value is number and should be align to right |
|
42
|
|
|
* @var boolean |
|
43
|
|
|
*/ |
|
44
|
|
|
private $isNumeric = false; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* number of decimals in numeric value |
|
48
|
|
|
* @var integer |
|
49
|
|
|
*/ |
|
50
|
|
|
private $decimals = 0; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* value is size and will be formatted as size |
|
54
|
|
|
* @var boolean |
|
55
|
|
|
*/ |
|
56
|
|
|
private $isSize = false; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* value is time and will be formatted as time |
|
60
|
|
|
* @var boolean |
|
61
|
|
|
*/ |
|
62
|
|
|
private $isTime = false; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* extended info about column |
|
66
|
|
|
* @var string |
|
67
|
|
|
*/ |
|
68
|
|
|
private $info; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* link to extended info about column |
|
72
|
|
|
* @var string |
|
73
|
|
|
*/ |
|
74
|
|
|
private $infoUrl; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* external url settings for related items |
|
78
|
|
|
* consists of 3 parts: |
|
79
|
|
|
* - database - database name |
|
80
|
|
|
* - table - table name |
|
81
|
|
|
* - callback - function to create item identifier |
|
82
|
|
|
* @var array |
|
83
|
|
|
*/ |
|
84
|
|
|
private $external = []; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param string $key key in item result array |
|
88
|
|
|
* @param string $title title (string is translated in template) |
|
89
|
|
|
*/ |
|
90
|
24 |
|
public function __construct($key, $title) |
|
91
|
|
|
{ |
|
92
|
24 |
|
$this->key = $key; |
|
93
|
24 |
|
$this->title = $title; |
|
94
|
24 |
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
4 |
|
public function getKey() |
|
100
|
|
|
{ |
|
101
|
4 |
|
return $this->key; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
4 |
|
public function getTitle() |
|
108
|
|
|
{ |
|
109
|
4 |
|
return $this->title; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param boolean $isSortable |
|
114
|
|
|
* @return Column |
|
115
|
|
|
*/ |
|
116
|
22 |
|
public function setSortable($isSortable) |
|
117
|
|
|
{ |
|
118
|
22 |
|
$this->isSortable = $isSortable; |
|
119
|
22 |
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return boolean |
|
124
|
|
|
*/ |
|
125
|
4 |
|
public function isSortable() |
|
126
|
|
|
{ |
|
127
|
4 |
|
return $this->isSortable; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param boolean $isFilterable |
|
132
|
|
|
* @param array $filters list of available filters for column |
|
133
|
|
|
* @return Column |
|
134
|
|
|
*/ |
|
135
|
8 |
|
public function setFilterable($isFilterable, array $filters = Filter::DEFAULT_FILTER_OPERATORS) |
|
136
|
|
|
{ |
|
137
|
8 |
|
$this->isFilterable = $isFilterable; |
|
138
|
8 |
|
$this->filters = $filters; |
|
139
|
8 |
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return boolean |
|
144
|
|
|
*/ |
|
145
|
4 |
|
public function isFilterable() |
|
146
|
|
|
{ |
|
147
|
4 |
|
return $this->isFilterable; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return array |
|
152
|
|
|
*/ |
|
153
|
4 |
|
public function getFilters() |
|
154
|
|
|
{ |
|
155
|
4 |
|
return $this->filters; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @param boolean $isNumeric |
|
160
|
|
|
* @return Column |
|
161
|
|
|
*/ |
|
162
|
22 |
|
public function setNumeric($isNumeric) |
|
163
|
|
|
{ |
|
164
|
22 |
|
$this->isNumeric = $isNumeric; |
|
165
|
22 |
|
return $this; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @return boolean |
|
170
|
|
|
*/ |
|
171
|
4 |
|
public function isNumeric() |
|
172
|
|
|
{ |
|
173
|
4 |
|
return $this->isNumeric; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param integer $decimals |
|
178
|
|
|
* @return Column |
|
179
|
|
|
*/ |
|
180
|
4 |
|
public function setDecimals($decimals) |
|
181
|
|
|
{ |
|
182
|
4 |
|
$this->decimals = $decimals; |
|
183
|
4 |
|
return $this; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @return integer |
|
188
|
|
|
*/ |
|
189
|
4 |
|
public function getDecimals() |
|
190
|
|
|
{ |
|
191
|
4 |
|
return $this->decimals; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @param boolean $isSize |
|
196
|
|
|
* @return Column |
|
197
|
|
|
*/ |
|
198
|
10 |
|
public function setSize($isSize) |
|
199
|
|
|
{ |
|
200
|
10 |
|
$this->isSize = $isSize; |
|
201
|
10 |
|
return $this; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @return boolean |
|
206
|
|
|
*/ |
|
207
|
4 |
|
public function isSize() |
|
208
|
|
|
{ |
|
209
|
4 |
|
return $this->isSize; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @param boolean $isTime |
|
214
|
|
|
* @return Column |
|
215
|
|
|
*/ |
|
216
|
10 |
|
public function setTime($isTime) |
|
217
|
|
|
{ |
|
218
|
10 |
|
$this->isTime = $isTime; |
|
219
|
10 |
|
return $this; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @return boolean |
|
224
|
|
|
*/ |
|
225
|
4 |
|
public function isTime() |
|
226
|
|
|
{ |
|
227
|
4 |
|
return $this->isTime; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @param string $info |
|
232
|
|
|
* @return Column |
|
233
|
|
|
*/ |
|
234
|
2 |
|
public function setInfo($info) |
|
235
|
|
|
{ |
|
236
|
2 |
|
$this->info = $info; |
|
237
|
2 |
|
return $this; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* @return string |
|
242
|
|
|
*/ |
|
243
|
4 |
|
public function getInfo() |
|
244
|
|
|
{ |
|
245
|
4 |
|
return $this->info; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* @param string $infoUrl |
|
250
|
|
|
* @return Column |
|
251
|
|
|
*/ |
|
252
|
2 |
|
public function setInfoUrl($infoUrl) |
|
253
|
|
|
{ |
|
254
|
2 |
|
$this->infoUrl = $infoUrl; |
|
255
|
2 |
|
return $this; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @return string |
|
260
|
|
|
*/ |
|
261
|
4 |
|
public function getInfoUrl() |
|
262
|
|
|
{ |
|
263
|
4 |
|
return $this->infoUrl; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @param string $database |
|
268
|
|
|
* @param string $table |
|
269
|
|
|
* @param Closure $callback function to create item identifier |
|
270
|
|
|
* @return Column |
|
271
|
|
|
*/ |
|
272
|
2 |
|
public function setExternal($database, $table, Closure $callback) |
|
273
|
|
|
{ |
|
274
|
2 |
|
$this->external = [ |
|
275
|
2 |
|
'database' => $database, |
|
276
|
2 |
|
'table' => $table, |
|
277
|
2 |
|
'callback' => $callback, |
|
278
|
|
|
]; |
|
279
|
2 |
|
return $this; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* @return array |
|
284
|
|
|
*/ |
|
285
|
4 |
|
public function getExternal() |
|
286
|
|
|
{ |
|
287
|
4 |
|
return $this->external; |
|
288
|
|
|
} |
|
289
|
|
|
} |
|
290
|
|
|
|