1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the jquery-datatables-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\JQuery\DataTablesBundle\Model; |
13
|
|
|
|
14
|
|
|
use InvalidArgumentException; |
15
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesColumnInterface; |
16
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesMappingInterface; |
17
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesSearchInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* DataTables column. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Model |
24
|
|
|
*/ |
25
|
|
|
class DataTablesColumn implements DataTablesColumnInterface { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Cell type. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $cellType; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class name. |
36
|
|
|
* |
37
|
|
|
* @var string|null |
38
|
|
|
*/ |
39
|
|
|
private $classname; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Content padding. |
43
|
|
|
* |
44
|
|
|
* @var string|null |
45
|
|
|
*/ |
46
|
|
|
private $contentPadding; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Data. |
50
|
|
|
* |
51
|
|
|
* @var string|null |
52
|
|
|
*/ |
53
|
|
|
private $data; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Default content. |
57
|
|
|
* |
58
|
|
|
* @var string|null |
59
|
|
|
*/ |
60
|
|
|
private $defaultContent; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* mapping. |
64
|
|
|
* |
65
|
|
|
* @var DataTablesMappingInterface |
66
|
|
|
*/ |
67
|
|
|
private $mapping; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Name. |
71
|
|
|
* |
72
|
|
|
* @var string|null |
73
|
|
|
*/ |
74
|
|
|
private $name; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Order data. |
78
|
|
|
* |
79
|
|
|
* @var array|null |
80
|
|
|
*/ |
81
|
|
|
private $orderData; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Order data type. |
85
|
|
|
* |
86
|
|
|
* @var string|null |
87
|
|
|
*/ |
88
|
|
|
private $orderDataType; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Order sequence. |
92
|
|
|
* |
93
|
|
|
* @var string|null |
94
|
|
|
*/ |
95
|
|
|
private $orderSequence; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Orderable. |
99
|
|
|
* |
100
|
|
|
* @var bool |
101
|
|
|
*/ |
102
|
|
|
private $orderable; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Search. |
106
|
|
|
* |
107
|
|
|
* @var DataTablesSearchInterface|null |
108
|
|
|
*/ |
109
|
|
|
private $search; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Searchable. |
113
|
|
|
* |
114
|
|
|
* @var bool |
115
|
|
|
*/ |
116
|
|
|
private $searchable; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Title. |
120
|
|
|
* |
121
|
|
|
* @var string|null |
122
|
|
|
*/ |
123
|
|
|
private $title; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Type. |
127
|
|
|
* |
128
|
|
|
* @var string|null |
129
|
|
|
*/ |
130
|
|
|
private $type; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Visible. |
134
|
|
|
* |
135
|
|
|
* @var bool |
136
|
|
|
*/ |
137
|
|
|
private $visible; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Width. |
141
|
|
|
* |
142
|
|
|
* @var string|null |
143
|
|
|
*/ |
144
|
|
|
private $width; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Constructor. |
148
|
|
|
*/ |
149
|
|
|
public function __construct() { |
150
|
|
|
$this->setCellType(self::DATATABLES_CELL_TYPE_TD); |
151
|
|
|
$this->setMapping(new DataTablesMapping()); |
152
|
|
|
$this->setOrderable(true); |
153
|
|
|
$this->setSearchable(true); |
154
|
|
|
$this->setVisible(true); |
155
|
|
|
|
156
|
|
|
$this->getMapping()->setParent($this); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* {@inheritDoc} |
161
|
|
|
*/ |
162
|
|
|
public function getCellType(): string { |
163
|
|
|
return $this->cellType; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* {@inheritDoc} |
168
|
|
|
*/ |
169
|
|
|
public function getClassname(): ?string { |
170
|
|
|
return $this->classname; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* {@inheritDoc} |
175
|
|
|
*/ |
176
|
|
|
public function getContentPadding(): ?string { |
177
|
|
|
return $this->contentPadding; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* {@inheritDoc} |
182
|
|
|
*/ |
183
|
|
|
public function getData(): ?string { |
184
|
|
|
return $this->data; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* {@inheritDoc} |
189
|
|
|
*/ |
190
|
|
|
public function getDefaultContent(): ?string { |
191
|
|
|
return $this->defaultContent; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* {@inheritDoc} |
196
|
|
|
*/ |
197
|
|
|
public function getMapping(): DataTablesMappingInterface { |
198
|
|
|
return $this->mapping; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* {@inheritDoc} |
203
|
|
|
*/ |
204
|
|
|
public function getName(): ?string { |
205
|
|
|
return $this->name; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* {@inheritDoc} |
210
|
|
|
*/ |
211
|
|
|
public function getOrderData(): ?array { |
212
|
|
|
return $this->orderData; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* {@inheritDoc} |
217
|
|
|
*/ |
218
|
|
|
public function getOrderDataType(): ?string { |
219
|
|
|
return $this->orderDataType; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* {@inheritDoc} |
224
|
|
|
*/ |
225
|
|
|
public function getOrderSequence(): ?string { |
226
|
|
|
return $this->orderSequence; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* {@inheritDoc} |
231
|
|
|
*/ |
232
|
|
|
public function getOrderable(): bool { |
233
|
|
|
return $this->orderable; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* {@inheritDoc} |
238
|
|
|
*/ |
239
|
|
|
public function getSearch(): ?DataTablesSearchInterface { |
240
|
|
|
return $this->search; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* {@inheritDoc} |
245
|
|
|
*/ |
246
|
|
|
public function getSearchable(): bool { |
247
|
|
|
return $this->searchable; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* {@inheritDoc} |
252
|
|
|
*/ |
253
|
|
|
public function getTitle(): ?string { |
254
|
|
|
return $this->title; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* {@inheritDoc} |
259
|
|
|
*/ |
260
|
|
|
public function getType(): ?string { |
261
|
|
|
return $this->type; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* {@inheritDoc} |
266
|
|
|
*/ |
267
|
|
|
public function getVisible(): bool { |
268
|
|
|
return $this->visible; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* {@inheritDoc} |
273
|
|
|
*/ |
274
|
|
|
public function getWidth(): ?string { |
275
|
|
|
return $this->width; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* {@inheritDoc} |
280
|
|
|
*/ |
281
|
|
|
public function setCellType(string $cellType): DataTablesColumnInterface { |
282
|
|
|
if (false === in_array($cellType, DataTablesEnumerator::enumCellTypes())) { |
283
|
|
|
$cellType = self::DATATABLES_CELL_TYPE_TD; |
284
|
|
|
} |
285
|
|
|
$this->cellType = $cellType; |
286
|
|
|
return $this; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* {@inheritDoc} |
291
|
|
|
*/ |
292
|
|
|
public function setClassname(?string $classname): DataTablesColumnInterface { |
293
|
|
|
$this->classname = $classname; |
294
|
|
|
return $this; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* {@inheritDoc} |
299
|
|
|
*/ |
300
|
|
|
public function setContentPadding(?string $contentPadding): DataTablesColumnInterface { |
301
|
|
|
$this->contentPadding = $contentPadding; |
302
|
|
|
return $this; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* Set the data. |
307
|
|
|
* |
308
|
|
|
* @param string|null $data The data. |
309
|
|
|
* @return DataTablesColumnInterface Returns this column. |
310
|
|
|
*/ |
311
|
|
|
public function setData(?string $data): DataTablesColumnInterface { |
312
|
|
|
$this->data = $data; |
313
|
|
|
return $this; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* {@inheritDoc} |
318
|
|
|
*/ |
319
|
|
|
public function setDefaultContent(?string $defaultContent): DataTablesColumnInterface { |
320
|
|
|
$this->defaultContent = $defaultContent; |
321
|
|
|
return $this; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Set the mapping. |
326
|
|
|
* |
327
|
|
|
* @param DataTablesMappingInterface $mapping The mapping. |
328
|
|
|
* @return DataTablesColumnInterface Returns this column. |
329
|
|
|
*/ |
330
|
|
|
protected function setMapping(DataTablesMappingInterface $mapping): DataTablesColumnInterface { |
331
|
|
|
$this->mapping = $mapping; |
332
|
|
|
return $this; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Set the name. |
337
|
|
|
* |
338
|
|
|
* @param string|null $name The name. |
339
|
|
|
* @return DataTablesColumnInterface Returns this column. |
340
|
|
|
*/ |
341
|
|
|
public function setName(?string $name): DataTablesColumnInterface { |
342
|
|
|
$this->name = $name; |
343
|
|
|
return $this; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* Set the order data. |
348
|
|
|
* |
349
|
|
|
* @param array|null $orderData The order data. |
350
|
|
|
* @return DataTablesColumnInterface Returns this column. |
351
|
|
|
*/ |
352
|
|
|
public function setOrderData(?array $orderData): DataTablesColumnInterface { |
353
|
|
|
$this->orderData = $orderData; |
354
|
|
|
return $this; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Set the order data type. |
359
|
|
|
* |
360
|
|
|
* @param string|null $orderDataType The order data type. |
361
|
|
|
* @return DataTablesColumnInterface Returns this column. |
362
|
|
|
*/ |
363
|
|
|
public function setOrderDataType(?string $orderDataType): DataTablesColumnInterface { |
364
|
|
|
$this->orderDataType = $orderDataType; |
365
|
|
|
return $this; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Set the order sequence. |
370
|
|
|
* |
371
|
|
|
* @param string|null $orderSequence The order sequence. |
372
|
|
|
* @return DataTablesColumnInterface Returns this column. |
373
|
|
|
*/ |
374
|
|
|
public function setOrderSequence(?string $orderSequence): DataTablesColumnInterface { |
375
|
|
|
if (false === in_array($orderSequence, DataTablesEnumerator::enumOrderSequences())) { |
376
|
|
|
$orderSequence = null; |
377
|
|
|
} |
378
|
|
|
$this->orderSequence = $orderSequence; |
379
|
|
|
return $this; |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* {@inheritDoc} |
384
|
|
|
*/ |
385
|
|
|
public function setOrderable(bool $orderable): DataTablesColumnInterface { |
386
|
|
|
$this->orderable = $orderable; |
387
|
|
|
return $this; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* {@inheritDoc} |
392
|
|
|
*/ |
393
|
|
|
public function setSearch(?DataTablesSearchInterface $search): DataTablesColumnInterface { |
394
|
|
|
$this->search = $search; |
395
|
|
|
return $this; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* {@inheritDoc} |
400
|
|
|
*/ |
401
|
|
|
public function setSearchable(bool $searchable): DataTablesColumnInterface { |
402
|
|
|
$this->searchable = $searchable; |
403
|
|
|
return $this; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* {@inheritDoc} |
408
|
|
|
*/ |
409
|
|
|
public function setTitle(?string $title): DataTablesColumnInterface { |
410
|
|
|
$this->title = $title; |
411
|
|
|
return $this; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* {@inheritDoc} |
416
|
|
|
*/ |
417
|
|
|
public function setType(?string $type): DataTablesColumnInterface { |
418
|
|
|
if (false === in_array($type, DataTablesEnumerator::enumTypes())) { |
419
|
|
|
throw new InvalidArgumentException(sprintf('The type "%s" is invalid', $type)); |
420
|
|
|
} |
421
|
|
|
$this->type = $type; |
422
|
|
|
return $this; |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* {@inheritDoc} |
427
|
|
|
*/ |
428
|
|
|
public function setVisible(bool $visible): DataTablesColumnInterface { |
429
|
|
|
$this->visible = $visible; |
430
|
|
|
return $this; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* {@inheritDoc} |
435
|
|
|
*/ |
436
|
|
|
public function setWidth(?string $width): DataTablesColumnInterface { |
437
|
|
|
$this->width = $width; |
438
|
|
|
return $this; |
439
|
|
|
} |
440
|
|
|
} |
441
|
|
|
|