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 mixed[]|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
|
|
|
|
151
|
|
|
$dtMapping = (new DataTablesMapping())->setParent($this); |
152
|
|
|
|
153
|
|
|
$this->setCellType(self::DATATABLES_CELL_TYPE_TD); |
154
|
|
|
$this->setMapping($dtMapping); |
155
|
|
|
$this->setOrderable(true); |
156
|
|
|
$this->setSearchable(true); |
157
|
|
|
$this->setVisible(true); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* {@inheritDoc} |
162
|
|
|
*/ |
163
|
|
|
public function getCellType(): string { |
164
|
|
|
return $this->cellType; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* {@inheritDoc} |
169
|
|
|
*/ |
170
|
|
|
public function getClassname(): ?string { |
171
|
|
|
return $this->classname; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* {@inheritDoc} |
176
|
|
|
*/ |
177
|
|
|
public function getContentPadding(): ?string { |
178
|
|
|
return $this->contentPadding; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* {@inheritDoc} |
183
|
|
|
*/ |
184
|
|
|
public function getData(): ?string { |
185
|
|
|
return $this->data; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* {@inheritDoc} |
190
|
|
|
*/ |
191
|
|
|
public function getDefaultContent(): ?string { |
192
|
|
|
return $this->defaultContent; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* {@inheritDoc} |
197
|
|
|
*/ |
198
|
|
|
public function getMapping(): DataTablesMappingInterface { |
199
|
|
|
return $this->mapping; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* {@inheritDoc} |
204
|
|
|
*/ |
205
|
|
|
public function getName(): ?string { |
206
|
|
|
return $this->name; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* {@inheritDoc} |
211
|
|
|
*/ |
212
|
|
|
public function getOrderData(): ?array { |
213
|
|
|
return $this->orderData; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* {@inheritDoc} |
218
|
|
|
*/ |
219
|
|
|
public function getOrderDataType(): ?string { |
220
|
|
|
return $this->orderDataType; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* {@inheritDoc} |
225
|
|
|
*/ |
226
|
|
|
public function getOrderSequence(): ?string { |
227
|
|
|
return $this->orderSequence; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* {@inheritDoc} |
232
|
|
|
*/ |
233
|
|
|
public function getOrderable(): bool { |
234
|
|
|
return $this->orderable; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* {@inheritDoc} |
239
|
|
|
*/ |
240
|
|
|
public function getSearch(): ?DataTablesSearchInterface { |
241
|
|
|
return $this->search; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* {@inheritDoc} |
246
|
|
|
*/ |
247
|
|
|
public function getSearchable(): bool { |
248
|
|
|
return $this->searchable; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* {@inheritDoc} |
253
|
|
|
*/ |
254
|
|
|
public function getTitle(): ?string { |
255
|
|
|
return $this->title; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* {@inheritDoc} |
260
|
|
|
*/ |
261
|
|
|
public function getType(): ?string { |
262
|
|
|
return $this->type; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* {@inheritDoc} |
267
|
|
|
*/ |
268
|
|
|
public function getVisible(): bool { |
269
|
|
|
return $this->visible; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* {@inheritDoc} |
274
|
|
|
*/ |
275
|
|
|
public function getWidth(): ?string { |
276
|
|
|
return $this->width; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* {@inheritDoc} |
281
|
|
|
*/ |
282
|
|
|
public function setCellType(string $cellType): DataTablesColumnInterface { |
283
|
|
|
|
284
|
|
|
if (false === in_array($cellType, DataTablesEnumerator::enumCellTypes())) { |
285
|
|
|
$cellType = self::DATATABLES_CELL_TYPE_TD; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
$this->cellType = $cellType; |
289
|
|
|
return $this; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* {@inheritDoc} |
294
|
|
|
*/ |
295
|
|
|
public function setClassname(?string $classname): DataTablesColumnInterface { |
296
|
|
|
$this->classname = $classname; |
297
|
|
|
return $this; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* {@inheritDoc} |
302
|
|
|
*/ |
303
|
|
|
public function setContentPadding(?string $contentPadding): DataTablesColumnInterface { |
304
|
|
|
$this->contentPadding = $contentPadding; |
305
|
|
|
return $this; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Set the data. |
310
|
|
|
* |
311
|
|
|
* @param string|null $data The data. |
312
|
|
|
* @return DataTablesColumnInterface Returns this column. |
313
|
|
|
*/ |
314
|
|
|
public function setData(?string $data): DataTablesColumnInterface { |
315
|
|
|
$this->data = $data; |
316
|
|
|
return $this; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* {@inheritDoc} |
321
|
|
|
*/ |
322
|
|
|
public function setDefaultContent(?string $defaultContent): DataTablesColumnInterface { |
323
|
|
|
$this->defaultContent = $defaultContent; |
324
|
|
|
return $this; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* Set the mapping. |
329
|
|
|
* |
330
|
|
|
* @param DataTablesMappingInterface $mapping The mapping. |
331
|
|
|
* @return DataTablesColumnInterface Returns this column. |
332
|
|
|
*/ |
333
|
|
|
protected function setMapping(DataTablesMappingInterface $mapping): DataTablesColumnInterface { |
334
|
|
|
$this->mapping = $mapping; |
335
|
|
|
return $this; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Set the name. |
340
|
|
|
* |
341
|
|
|
* @param string|null $name The name. |
342
|
|
|
* @return DataTablesColumnInterface Returns this column. |
343
|
|
|
*/ |
344
|
|
|
public function setName(?string $name): DataTablesColumnInterface { |
345
|
|
|
$this->name = $name; |
346
|
|
|
return $this; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Set the order data. |
351
|
|
|
* |
352
|
|
|
* @param mixed[]|null $orderData The order data. |
353
|
|
|
* @return DataTablesColumnInterface Returns this column. |
354
|
|
|
*/ |
355
|
|
|
public function setOrderData(?array $orderData): DataTablesColumnInterface { |
356
|
|
|
$this->orderData = $orderData; |
357
|
|
|
return $this; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Set the order data type. |
362
|
|
|
* |
363
|
|
|
* @param string|null $orderDataType The order data type. |
364
|
|
|
* @return DataTablesColumnInterface Returns this column. |
365
|
|
|
*/ |
366
|
|
|
public function setOrderDataType(?string $orderDataType): DataTablesColumnInterface { |
367
|
|
|
$this->orderDataType = $orderDataType; |
368
|
|
|
return $this; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Set the order sequence. |
373
|
|
|
* |
374
|
|
|
* @param string|null $orderSequence The order sequence. |
375
|
|
|
* @return DataTablesColumnInterface Returns this column. |
376
|
|
|
*/ |
377
|
|
|
public function setOrderSequence(?string $orderSequence): DataTablesColumnInterface { |
378
|
|
|
|
379
|
|
|
if (false === in_array($orderSequence, DataTablesEnumerator::enumOrderSequences())) { |
380
|
|
|
$orderSequence = null; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
$this->orderSequence = $orderSequence; |
384
|
|
|
return $this; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* {@inheritDoc} |
389
|
|
|
*/ |
390
|
|
|
public function setOrderable(bool $orderable): DataTablesColumnInterface { |
391
|
|
|
$this->orderable = $orderable; |
392
|
|
|
return $this; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* {@inheritDoc} |
397
|
|
|
*/ |
398
|
|
|
public function setSearch(?DataTablesSearchInterface $search): DataTablesColumnInterface { |
399
|
|
|
$this->search = $search; |
400
|
|
|
return $this; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* {@inheritDoc} |
405
|
|
|
*/ |
406
|
|
|
public function setSearchable(bool $searchable): DataTablesColumnInterface { |
407
|
|
|
$this->searchable = $searchable; |
408
|
|
|
return $this; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* {@inheritDoc} |
413
|
|
|
*/ |
414
|
|
|
public function setTitle(?string $title): DataTablesColumnInterface { |
415
|
|
|
$this->title = $title; |
416
|
|
|
return $this; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* {@inheritDoc} |
421
|
|
|
*/ |
422
|
|
|
public function setType(?string $type): DataTablesColumnInterface { |
423
|
|
|
|
424
|
|
|
if (false === in_array($type, DataTablesEnumerator::enumTypes())) { |
425
|
|
|
throw new InvalidArgumentException(sprintf('The type "%s" is invalid', $type)); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
$this->type = $type; |
429
|
|
|
return $this; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* {@inheritDoc} |
434
|
|
|
*/ |
435
|
|
|
public function setVisible(bool $visible): DataTablesColumnInterface { |
436
|
|
|
$this->visible = $visible; |
437
|
|
|
return $this; |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* {@inheritDoc} |
442
|
|
|
*/ |
443
|
|
|
public function setWidth(?string $width): DataTablesColumnInterface { |
444
|
|
|
$this->width = $width; |
445
|
|
|
return $this; |
446
|
|
|
} |
447
|
|
|
} |
448
|
|
|
|