Completed
Push — master ( dbc0ff...b4a470 )
by WEBEWEB
01:31
created

DataTablesColumn::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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\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
     * @param string $name The column name.
141
     * @param string $title The column title.
142
     * @param string $cellType The column cell type.
143
     */
144
    public function __construct($name, $title, $cellType = "td") {
145
        $this->mapping = new DataTablesMapping();
146
        $this->mapping->setColumn($name);
147
148
        $this->setCellType($cellType);
149
        $this->setData($name);
150
        $this->setName($name);
151
        $this->setTitle($title);
152
    }
153
154
    /**
155
     * Get the cell type.
156
     *
157
     * @return string Returns the cell type.
158
     */
159
    public function getCellType() {
160
        return $this->cellType;
161
    }
162
163
    /**
164
     * Get the class name.
165
     *
166
     * @return string Returns the class name.
167
     */
168
    public function getClassname() {
169
        return $this->classname;
170
    }
171
172
    /**
173
     * Get the content padding.
174
     *
175
     * @return string Returns the content padding.
176
     */
177
    public function getContentPadding() {
178
        return $this->contentPadding;
179
    }
180
181
    /**
182
     * Get the data.
183
     *
184
     * @return integer|string Returns the data.
185
     */
186
    public function getData() {
187
        return $this->data;
188
    }
189
190
    /**
191
     * Get the default content
192
     *
193
     * @return string Returns the default content.
194
     */
195
    public function getDefaultContent() {
196
        return $this->defaultContent;
197
    }
198
199
    /**
200
     * Get the mapping.
201
     *
202
     * @return DataTablesMapping The mapping.
203
     */
204
    public function getMapping() {
205
        return $this->mapping;
206
    }
207
208
    /**
209
     * Get the name.
210
     *
211
     * @return string Returns the name.
212
     */
213
    public function getName() {
214
        return $this->name;
215
    }
216
217
    /**
218
     * Get the order data.
219
     *
220
     * @return integer|array Returns the order data.
221
     */
222
    public function getOrderData() {
223
        return $this->orderData;
224
    }
225
226
    /**
227
     * Get the order data type.
228
     *
229
     * @return string Returns the order data type.
230
     */
231
    public function getOrderDataType() {
232
        return $this->orderDataType;
233
    }
234
235
    /**
236
     * Get the order sequence.
237
     *
238
     * @return string Returns the order sequence.
239
     */
240
    public function getOrderSequence() {
241
        return $this->orderSequence;
242
    }
243
244
    /**
245
     * Get the orderable.
246
     *
247
     * @return boolean Returns the orderable.
248
     */
249
    public function getOrderable() {
250
        return $this->orderable;
251
    }
252
253
    /**
254
     * Get the searchable.
255
     *
256
     * @return boolean Returns the searchable.
257
     */
258
    public function getSearchable() {
259
        return $this->searchable;
260
    }
261
262
    /**
263
     * Get the title.
264
     *
265
     * @return string Returns the title.
266
     */
267
    public function getTitle() {
268
        return $this->title;
269
    }
270
271
    /**
272
     * Get the type.
273
     *
274
     * @return string Returns the type.
275
     */
276
    public function getType() {
277
        return $this->type;
278
    }
279
280
    /**
281
     * Get the visible.
282
     *
283
     * @return boolean Returns the visible.
284
     */
285
    public function getVisible() {
286
        return $this->visible;
287
    }
288
289
    /**
290
     * Get the width.
291
     *
292
     * @return string Returns the width.
293
     */
294
    public function getWidth() {
295
        return $this->width;
296
    }
297
298
    /**
299
     * {@inheritdoc}
300
     */
301
    public function jsonSerialize() {
302
        return $this->toArray();
303
    }
304
305
    /**
306
     * Set the cell type.
307
     *
308
     * @param string $cellType The cell type.
309
     * @return DataTablesColumn Returns this DataTables column.
310
     */
311
    public function setCellType($cellType) {
312
        switch ($cellType) {
313
            case "td":
314
            case "th":
315
                $this->cellType = $cellType;
316
                break;
317
            default:
318
                $this->cellType = "td";
319
        }
320
        return $this;
321
    }
322
323
    /**
324
     * Set the class name.
325
     *
326
     * @param string $classname The class name.
327
     * @return DataTablesColumn Returns this DataTables column.
328
     */
329
    public function setClassname($classname) {
330
        $this->classname = $classname;
331
        return $this;
332
    }
333
334
    /**
335
     * Set the content padding.
336
     *
337
     * @param string $contentPadding The content padding.
338
     * @return DataTablesColumn Returns this DataTables column.
339
     */
340
    public function setContentPadding($contentPadding) {
341
        $this->contentPadding = $contentPadding;
342
        return $this;
343
    }
344
345
    /**
346
     * Set the data.
347
     *
348
     * @param integer|string $data The data.
349
     * @return DataTablesColumn Returns this DataTables column.
350
     */
351
    public function setData($data) {
352
        $this->data = $data;
353
        return $this;
354
    }
355
356
    /**
357
     * Set the default content.
358
     *
359
     * @param string $defaultContent The default content.
360
     * @return DataTablesColumn Returns this DataTables column.
361
     */
362
    public function setDefaultContent($defaultContent) {
363
        $this->defaultContent = $defaultContent;
364
        return $this;
365
    }
366
367
    /**
368
     * Set the name.
369
     *
370
     * @param string $name The name.
371
     * @return DataTablesColumn Returns this DataTables column.
372
     */
373
    public function setName($name) {
374
        $this->name = $name;
375
        return $this;
376
    }
377
378
    /**
379
     * Set the order data.
380
     *
381
     * @param integer|array $orderData The order data.
382
     * @return DataTablesColumn Returns this DataTables column.
383
     */
384
    public function setOrderData($orderData) {
385
        $this->orderData = $orderData;
386
        return $this;
387
    }
388
389
    /**
390
     * Set the order data type.
391
     *
392
     * @param string $orderDataType The order data type.
393
     * @return DataTablesColumn Returns this DataTables column.
394
     */
395
    public function setOrderDataType($orderDataType) {
396
        $this->orderDataType = $orderDataType;
397
        return $this;
398
    }
399
400
    /**
401
     * Set the order sequence.
402
     *
403
     * @param string $orderSequence The order sequence.
404
     * @return DataTablesColumn Returns this DataTables column.
405
     */
406
    public function setOrderSequence($orderSequence) {
407
        switch ($orderSequence) {
408
            case "asc":
409
            case "desc":
410
                $this->orderSequence = $orderSequence;
411
                break;
412
            default:
413
                $this->orderSequence = null;
414
        }
415
        return $this;
416
    }
417
418
    /**
419
     * Set the orderable.
420
     *
421
     * @param boolean $orderable The orderable.
422
     * @return DataTablesColumn Returns this DataTables column.
423
     */
424
    public function setOrderable($orderable) {
425
        $this->orderable = $orderable;
426
        return $this;
427
    }
428
429
    /**
430
     * Set the searchable.
431
     *
432
     * @param boolean $searchable The searchable.
433
     * @return DataTablesColumn Returns this DataTables column.
434
     */
435
    public function setSearchable($searchable) {
436
        $this->searchable = $searchable;
437
        return $this;
438
    }
439
440
    /**
441
     * Set the title.
442
     *
443
     * @param string $title The title.
444
     * @return DataTablesColumn Returns this DataTables column.
445
     */
446
    public function setTitle($title) {
447
        $this->title = $title;
448
        return $this;
449
    }
450
451
    /**
452
     * Set the type.
453
     *
454
     * @param string $type The type.
455
     * @return DataTablesColumn Returns this DataTables column.
456
     */
457
    public function setType($type) {
458
        switch ($type) {
459
            case "date":
460
            case "num":
461
            case "num-fmt":
462
            case "html":
463
            case "html-num":
464
            case "string":
465
                $this->type = $type;
466
                break;
467
            default:
468
                $this->type = null;
469
        }
470
        return $this;
471
    }
472
473
    /**
474
     * Set the visible.
475
     *
476
     * @param boolean $visible The visible.
477
     * @return DataTablesColumn Returns this DataTables column.
478
     */
479
    public function setVisible($visible) {
480
        $this->visible = $visible;
481
        return $this;
482
    }
483
484
    /**
485
     * Set the width.
486
     *
487
     * @param string $width The width.
488
     * @return DataTablesColumn Returns this DataTables column.
489
     */
490
    public function setWidth($width) {
491
        $this->width = $width;
492
        return $this;
493
    }
494
495
    /**
496
     * Convert into an array representing this instance.
497
     *
498
     * @return array Returns an array representing this instance.
499
     */
500
    public function toArray() {
501
502
        // Initialize the output.
503
        $output = [];
504
505
        ArrayUtility::set($output, "cellType", $this->cellType, [null]);
506
        ArrayUtility::set($output, "classname", $this->classname, [null]);
507
        ArrayUtility::set($output, "contentPadding", $this->contentPadding, [null]);
508
        ArrayUtility::set($output, "data", $this->data, [null]);
509
        ArrayUtility::set($output, "defaultContent", $this->defaultContent, [null]);
510
        ArrayUtility::set($output, "name", $this->name, [null]);
511
        ArrayUtility::set($output, "orderable", $this->orderable, [null, true]);
512
        ArrayUtility::set($output, "orderData", $this->orderData, [null]);
513
        ArrayUtility::set($output, "orderDataType", $this->orderDataType, [null]);
514
        ArrayUtility::set($output, "orderSequence", $this->orderSequence, [null]);
515
        ArrayUtility::set($output, "searchable", $this->searchable, [null, true]);
516
        ArrayUtility::set($output, "title", $this->title, [null]);
517
        ArrayUtility::set($output, "type", $this->type, [null]);
518
        ArrayUtility::set($output, "visible", $this->visible, [null, true]);
519
        ArrayUtility::set($output, "width", $this->width, [null]);
520
521
        // Return the output.
522
        return $output;
523
    }
524
525
}
526