Completed
Push — master ( d0e1f9...0b41f4 )
by WEBEWEB
01:24
created

DataTablesColumn::setVisible()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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