Completed
Push — master ( aa1ff9...583713 )
by WEBEWEB
06:13
created

DataTablesColumn::toArray()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 1
eloc 18
nc 1
nop 0
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\Column;
13
14
use JsonSerializable;
15
use WBW\Bundle\JQuery\DatatablesBundle\Mapping\DataTablesMapping;
16
use WBW\Library\Core\Utility\ArrayUtility;
17
18
/**
19
 * DataTables column.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\JQuery\DatatablesBundle\Column
23
 * @final
24
 */
25
final class DataTablesColumn implements JsonSerializable {
26
27
    /**
28
     * Cell type.
29
     *
30
     * @var string
31
     */
32
    private $cellType = "td";
33
34
    /**
35
     * Class name.
36
     *
37
     * @var string
38
     */
39
    private $classname;
40
41
    /**
42
     * Content padding.
43
     *
44
     * @var string
45
     */
46
    private $contentPadding;
47
48
    /**
49
     * Data.
50
     *
51
     * @var integer|string
52
     */
53
    private $data;
54
55
    /**
56
     * Default content.
57
     *
58
     * @var string
59
     */
60
    private $defaultContent;
61
62
    /**
63
     * mapping.
64
     *
65
     * @var DataTablesMapping
66
     */
67
    private $mapping;
68
69
    /**
70
     * Name.
71
     *
72
     * @var string
73
     */
74
    private $name;
75
76
    /**
77
     * Order data.
78
     *
79
     * @var integer|array
80
     */
81
    private $orderData;
82
83
    /**
84
     * Order data type.
85
     *
86
     * @var string
87
     */
88
    private $orderDataType;
89
90
    /**
91
     * Order sequence.
92
     *
93
     * @var string
94
     */
95
    private $orderSequence;
96
97
    /**
98
     * Orderable.
99
     *
100
     * @var boolean
101
     */
102
    private $orderable = true;
103
104
    /**
105
     * Searchable.
106
     *
107
     * @var boolean
108
     */
109
    private $searchable = true;
110
111
    /**
112
     * Title.
113
     *
114
     * @var string
115
     */
116
    private $title;
117
118
    /**
119
     * Type.
120
     *
121
     * @var string
122
     */
123
    private $type;
124
125
    /**
126
     * Visible.
127
     *
128
     * @var boolean
129
     */
130
    private $visible = true;
131
132
    /**
133
     * Width.
134
     *
135
     * @var string
136
     */
137
    private $width;
138
139
    /**
140
     * Constructor.
141
     *
142
     * @param string $name The column name.
143
     * @param string $title The column title.
144
     * @param string $cellType The column cell type.
145
     */
146
    public function __construct($name, $title, $cellType = "td") {
147
        $this->mapping = new DataTablesMapping();
148
        $this->mapping->setColumn($name);
149
150
        $this->setCellType($cellType);
151
        $this->setData($name);
152
        $this->setName($name);
153
        $this->setTitle($title);
154
    }
155
156
    /**
157
     * Get the cell type.
158
     *
159
     * @return string Returns the cell type.
160
     */
161
    public function getCellType() {
162
        return $this->cellType;
163
    }
164
165
    /**
166
     * Get the class name.
167
     *
168
     * @return string Returns the class name.
169
     */
170
    public function getClassname() {
171
        return $this->classname;
172
    }
173
174
    /**
175
     * Get the content padding.
176
     *
177
     * @return string Returns the content padding.
178
     */
179
    public function getContentPadding() {
180
        return $this->contentPadding;
181
    }
182
183
    /**
184
     * Get the data.
185
     *
186
     * @return integer|string Returns the data.
187
     */
188
    public function getData() {
189
        return $this->data;
190
    }
191
192
    /**
193
     * Get the default content
194
     *
195
     * @return string Returns the default content.
196
     */
197
    public function getDefaultContent() {
198
        return $this->defaultContent;
199
    }
200
201
    /**
202
     * Get the mapping.
203
     *
204
     * @return DataTablesMapping The mapping.
205
     */
206
    public function getMapping() {
207
        return $this->mapping;
208
    }
209
210
    /**
211
     * Get the name.
212
     *
213
     * @return string Returns the name.
214
     */
215
    public function getName() {
216
        return $this->name;
217
    }
218
219
    /**
220
     * Get the order data.
221
     *
222
     * @return integer|array Returns the order data.
223
     */
224
    public function getOrderData() {
225
        return $this->orderData;
226
    }
227
228
    /**
229
     * Get the order data type.
230
     *
231
     * @return string Returns the order data type.
232
     */
233
    public function getOrderDataType() {
234
        return $this->orderDataType;
235
    }
236
237
    /**
238
     * Get the order sequence.
239
     *
240
     * @return string Returns the order sequence.
241
     */
242
    public function getOrderSequence() {
243
        return $this->orderSequence;
244
    }
245
246
    /**
247
     * Get the orderable.
248
     *
249
     * @return boolean Returns the orderable.
250
     */
251
    public function getOrderable() {
252
        return $this->orderable;
253
    }
254
255
    /**
256
     * Get the searchable.
257
     *
258
     * @return boolean Returns the searchable.
259
     */
260
    public function getSearchable() {
261
        return $this->searchable;
262
    }
263
264
    /**
265
     * Get the title.
266
     *
267
     * @return string Returns the title.
268
     */
269
    public function getTitle() {
270
        return $this->title;
271
    }
272
273
    /**
274
     * Get the type.
275
     *
276
     * @return string Returns the type.
277
     */
278
    public function getType() {
279
        return $this->type;
280
    }
281
282
    /**
283
     * Get the visible.
284
     *
285
     * @return boolean Returns the visible.
286
     */
287
    public function getVisible() {
288
        return $this->visible;
289
    }
290
291
    /**
292
     * Get the width.
293
     *
294
     * @return string Returns the width.
295
     */
296
    public function getWidth() {
297
        return $this->width;
298
    }
299
300
    /**
301
     * {@inheritdoc}
302
     */
303
    public function jsonSerialize() {
304
        return $this->toArray();
305
    }
306
307
    /**
308
     * Set the cell type.
309
     *
310
     * @param string $cellType The cell type.
311
     * @return DataTablesColumn Returns the DataTables column.
312
     */
313
    public function setCellType($cellType) {
314
        switch ($cellType) {
315
            case "td":
316
            case "th":
317
                $this->cellType = $cellType;
318
                break;
319
            default:
320
                $this->cellType = "td";
321
        }
322
        return $this;
323
    }
324
325
    /**
326
     * Set the class name.
327
     *
328
     * @param string $classname The class name.
329
     * @return DataTablesColumn Returns the DataTables column.
330
     */
331
    public function setClassname($classname) {
332
        $this->classname = $classname;
333
        return $this;
334
    }
335
336
    /**
337
     * Set the content padding.
338
     *
339
     * @param string $contentPadding The content padding.
340
     * @return DataTablesColumn Returns the DataTables column.
341
     */
342
    public function setContentPadding($contentPadding) {
343
        $this->contentPadding = $contentPadding;
344
        return $this;
345
    }
346
347
    /**
348
     * Set the data.
349
     *
350
     * @param integer|string $data The data.
351
     * @return DataTablesColumn Returns the DataTables column.
352
     */
353
    public function setData($data) {
354
        $this->data = $data;
355
        return $this;
356
    }
357
358
    /**
359
     * Set the default content.
360
     *
361
     * @param string $defaultContent The default content.
362
     * @return DataTablesColumn Returns the DataTables column.
363
     */
364
    public function setDefaultContent($defaultContent) {
365
        $this->defaultContent = $defaultContent;
366
        return $this;
367
    }
368
369
    /**
370
     * Set the name.
371
     *
372
     * @param string $name The name.
373
     * @return DataTablesColumn Returns the DataTables column.
374
     */
375
    public function setName($name) {
376
        $this->name = $name;
377
        return $this;
378
    }
379
380
    /**
381
     * Set the order data.
382
     *
383
     * @param integer|array $orderData The order data.
384
     * @return DataTablesColumn Returns the DataTables column.
385
     */
386
    public function setOrderData($orderData) {
387
        $this->orderData = $orderData;
388
        return $this;
389
    }
390
391
    /**
392
     * Set the order data type.
393
     *
394
     * @param string $orderDataType The order data type.
395
     * @return DataTablesColumn Returns the DataTables column.
396
     */
397
    public function setOrderDataType($orderDataType) {
398
        $this->orderDataType = $orderDataType;
399
        return $this;
400
    }
401
402
    /**
403
     * Set the order sequence.
404
     *
405
     * @param string $orderSequence The order sequence.
406
     * @return DataTablesColumn Returns the DataTables column.
407
     */
408
    public function setOrderSequence($orderSequence) {
409
        switch ($orderSequence) {
410
            case "asc":
411
            case "desc":
412
                $this->orderSequence = $orderSequence;
413
                break;
414
            default:
415
                $this->orderSequence = null;
416
        }
417
        return $this;
418
    }
419
420
    /**
421
     * Set the orderable.
422
     *
423
     * @param boolean $orderable The orderable.
424
     * @return DataTablesColumn Returns the DataTables column.
425
     */
426
    public function setOrderable($orderable) {
427
        $this->orderable = $orderable;
428
        return $this;
429
    }
430
431
    /**
432
     * Set the searchable.
433
     *
434
     * @param boolean $searchable The searchable.
435
     * @return DataTablesColumn Returns the DataTables column.
436
     */
437
    public function setSearchable($searchable) {
438
        $this->searchable = $searchable;
439
        return $this;
440
    }
441
442
    /**
443
     * Set the title.
444
     *
445
     * @param string $title The title.
446
     * @return DataTablesColumn Returns the DataTables column.
447
     */
448
    public function setTitle($title) {
449
        $this->title = $title;
450
        return $this;
451
    }
452
453
    /**
454
     * Set the type.
455
     *
456
     * @param string $type The type.
457
     * @return DataTablesColumn Returns the DataTables column.
458
     */
459
    public function setType($type) {
460
        switch ($type) {
461
            case "date":
462
            case "num":
463
            case "num-fmt":
464
            case "html":
465
            case "html-num":
466
            case "string":
467
                $this->type = $type;
468
                break;
469
            default:
470
                $this->type = null;
471
        }
472
        return $this;
473
    }
474
475
    /**
476
     * Set the visible.
477
     *
478
     * @param boolean $visible The visible.
479
     * @return DataTablesColumn Returns the DataTables column.
480
     */
481
    public function setVisible($visible) {
482
        $this->visible = $visible;
483
        return $this;
484
    }
485
486
    /**
487
     * Set the width.
488
     *
489
     * @param string $width The width.
490
     * @return DataTablesColumn Returns the DataTables column.
491
     */
492
    public function setWidth($width) {
493
        $this->width = $width;
494
        return $this;
495
    }
496
497
    /**
498
     * Convert into an array representing this instance.
499
     *
500
     * @return array Returns an array representing this instance.
501
     */
502
    public function toArray() {
503
504
        // Initialize the output.
505
        $output = [];
506
507
        ArrayUtility::set($output, "cellType", $this->cellType, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
508
        ArrayUtility::set($output, "classname", $this->classname, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
509
        ArrayUtility::set($output, "contentPadding", $this->contentPadding, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
510
        ArrayUtility::set($output, "data", $this->data, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
511
        ArrayUtility::set($output, "defaultContent", $this->defaultContent, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
512
        ArrayUtility::set($output, "name", $this->name, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
513
        ArrayUtility::set($output, "orderable", $this->orderable, [null, true]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
514
        ArrayUtility::set($output, "orderData", $this->orderData, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
515
        ArrayUtility::set($output, "orderDataType", $this->orderDataType, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
516
        ArrayUtility::set($output, "orderSequence", $this->orderSequence, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
517
        ArrayUtility::set($output, "searchable", $this->searchable, [null, true]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
518
        ArrayUtility::set($output, "title", $this->title, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
519
        ArrayUtility::set($output, "type", $this->type, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
520
        ArrayUtility::set($output, "visible", $this->visible, [null, true]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
521
        ArrayUtility::set($output, "width", $this->width, [null]);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<WBW\Library\Core\Utility\ArrayUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
522
523
        // Return the output.
524
        return $output;
525
    }
526
527
}
528