Completed
Push — master ( 16d0ae...028c32 )
by WEBEWEB
02:00
created

DataTablesColumn::getCellType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
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\Bundle\JQuery\DataTablesBundle\Helper\DataTablesColumnHelper;
16
use WBW\Library\Core\Argument\ArrayHelper;
17
18
/**
19
 * DataTables column.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\JQuery\DataTablesBundle\API
23
 */
24
class DataTablesColumn implements DataTablesColumnInterface, JsonSerializable {
25
26
    /**
27
     * Cell type.
28
     *
29
     * @var string
30
     */
31
    private $cellType;
32
33
    /**
34
     * Class name.
35
     *
36
     * @var string
37
     */
38
    private $classname;
39
40
    /**
41
     * Content padding.
42
     *
43
     * @var string
44
     */
45
    private $contentPadding;
46
47
    /**
48
     * Data.
49
     *
50
     * @var integer|string
51
     */
52
    private $data;
53
54
    /**
55
     * Default content.
56
     *
57
     * @var string
58
     */
59
    private $defaultContent;
60
61
    /**
62
     * mapping.
63
     *
64
     * @var DataTablesMappingInterface
65
     */
66
    private $mapping;
67
68
    /**
69
     * Name.
70
     *
71
     * @var string
72
     */
73
    private $name;
74
75
    /**
76
     * Order data.
77
     *
78
     * @var integer|array
79
     */
80
    private $orderData;
81
82
    /**
83
     * Order data type.
84
     *
85
     * @var string
86
     */
87
    private $orderDataType;
88
89
    /**
90
     * Order sequence.
91
     *
92
     * @var string
93
     */
94
    private $orderSequence;
95
96
    /**
97
     * Orderable.
98
     *
99
     * @var bool
100
     */
101
    private $orderable;
102
103
    /**
104
     * Search.
105
     *
106
     * @var DataTablesSearchInterface
107
     */
108
    private $search;
109
110
    /**
111
     * Searchable.
112
     *
113
     * @var bool
114
     */
115
    private $searchable;
116
117
    /**
118
     * Title.
119
     *
120
     * @var string
121
     */
122
    private $title;
123
124
    /**
125
     * Type.
126
     *
127
     * @var string
128
     */
129
    private $type;
130
131
    /**
132
     * Visible.
133
     *
134
     * @var bool
135
     */
136
    private $visible;
137
138
    /**
139
     * Width.
140
     *
141
     * @var string
142
     */
143
    private $width;
144
145
    /**
146
     * Constructor.
147
     */
148
    public function __construct() {
149
        $this->setCellType(self::DATATABLES_CELL_TYPE_TD);
150
        $this->setMapping(new DataTablesMapping());
151
        $this->setOrderable(true);
152
        $this->setSearchable(true);
153
        $this->setVisible(true);
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 DataTablesMappingInterface 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 bool Returns the orderable.
250
     */
251
    public function getOrderable() {
252
        return $this->orderable;
253
    }
254
255
    /**
256
     * Get the search.
257
     *
258
     * @return DataTablesSearchInterface Returns the search.
259
     */
260
    public function getSearch() {
261
        return $this->search;
262
    }
263
264
    /**
265
     * Get the searchable.
266
     *
267
     * @return bool Returns the searchable.
268
     */
269
    public function getSearchable() {
270
        return $this->searchable;
271
    }
272
273
    /**
274
     * Get the title.
275
     *
276
     * @return string Returns the title.
277
     */
278
    public function getTitle() {
279
        return $this->title;
280
    }
281
282
    /**
283
     * Get the type.
284
     *
285
     * @return string Returns the type.
286
     */
287
    public function getType() {
288
        return $this->type;
289
    }
290
291
    /**
292
     * Get the visible.
293
     *
294
     * @return bool Returns the visible.
295
     */
296
    public function getVisible() {
297
        return $this->visible;
298
    }
299
300
    /**
301
     * Get the width.
302
     *
303
     * @return string Returns the width.
304
     */
305
    public function getWidth() {
306
        return $this->width;
307
    }
308
309
    /**
310
     * {@inheritdoc}
311
     */
312
    public function jsonSerialize() {
313
        return $this->toArray();
314
    }
315
316
    /**
317
     * Create a column instance.
318
     *
319
     * @param string $data The column data.
320
     * @param string $name The column name.
321
     * @param string $cellType The column cell type.
322
     * @return DataTablesColumn Returns a column.
323
     */
324
    public static function newInstance($data, $name, $cellType = self::DATATABLES_CELL_TYPE_TD) {
325
326
        // Initialize a column.
327
        $dtColumn = new DataTablesColumn();
328
        $dtColumn->setCellType($cellType);
329
        $dtColumn->setData($data);
330
        $dtColumn->setName($name);
331
        $dtColumn->setTitle($name);
332
        $dtColumn->getMapping()->setColumn($data);
333
334
        // Return the column.
335
        return $dtColumn;
336
    }
337
338
    /**
339
     * Set the cell type.
340
     *
341
     * @param string $cellType The cell type.
342
     * @return DataTablesColumn Returns this column.
343
     */
344
    public function setCellType($cellType) {
345
        if (false === in_array($cellType, DataTablesColumnHelper::dtCellTypes())) {
346
            $cellType = self::DATATABLES_CELL_TYPE_TD;
347
        }
348
        $this->cellType = $cellType;
349
        return $this;
350
    }
351
352
    /**
353
     * Set the class name.
354
     *
355
     * @param string $classname The class name.
356
     * @return DataTablesColumn Returns this column.
357
     */
358
    public function setClassname($classname) {
359
        $this->classname = $classname;
360
        return $this;
361
    }
362
363
    /**
364
     * Set the content padding.
365
     *
366
     * @param string $contentPadding The content padding.
367
     * @return DataTablesColumn Returns this column.
368
     */
369
    public function setContentPadding($contentPadding) {
370
        $this->contentPadding = $contentPadding;
371
        return $this;
372
    }
373
374
    /**
375
     * Set the data.
376
     *
377
     * @param integer|string $data The data.
378
     * @return DataTablesColumn Returns this column.
379
     */
380
    public function setData($data) {
381
        $this->data = $data;
382
        return $this;
383
    }
384
385
    /**
386
     * Set the default content.
387
     *
388
     * @param string $defaultContent The default content.
389
     * @return DataTablesColumn Returns this column.
390
     */
391
    public function setDefaultContent($defaultContent) {
392
        $this->defaultContent = $defaultContent;
393
        return $this;
394
    }
395
396
    /**
397
     * Set the mapping.
398
     *
399
     * @param DataTablesMappingInterface $mapping The mapping.
400
     * @return DataTablesColumn Returns this column.
401
     */
402
    protected function setMapping(DataTablesMappingInterface $mapping) {
403
        $this->mapping = $mapping;
404
        return $this;
405
    }
406
407
    /**
408
     * Set the name.
409
     *
410
     * @param string $name The name.
411
     * @return DataTablesColumn Returns this column.
412
     */
413
    public function setName($name) {
414
        $this->name = $name;
415
        return $this;
416
    }
417
418
    /**
419
     * Set the order data.
420
     *
421
     * @param integer|array $orderData The order data.
422
     * @return DataTablesColumn Returns this column.
423
     */
424
    public function setOrderData($orderData) {
425
        $this->orderData = $orderData;
426
        return $this;
427
    }
428
429
    /**
430
     * Set the order data type.
431
     *
432
     * @param string $orderDataType The order data type.
433
     * @return DataTablesColumn Returns this column.
434
     */
435
    public function setOrderDataType($orderDataType) {
436
        $this->orderDataType = $orderDataType;
437
        return $this;
438
    }
439
440
    /**
441
     * Set the order sequence.
442
     *
443
     * @param string $orderSequence The order sequence.
444
     * @return DataTablesColumn Returns this column.
445
     */
446
    public function setOrderSequence($orderSequence) {
447
        if (false === in_array($orderSequence, DataTablesColumnHelper::dtOrderSequences())) {
448
            $orderSequence = null;
449
        }
450
        $this->orderSequence = $orderSequence;
451
        return $this;
452
    }
453
454
    /**
455
     * Set the orderable.
456
     *
457
     * @param bool $orderable The orderable.
458
     * @return DataTablesColumn Returns this column.
459
     */
460
    public function setOrderable($orderable) {
461
        $this->orderable = $orderable;
462
        return $this;
463
    }
464
465
    /**
466
     * Set the search.
467
     *
468
     * @param DataTablesSearchInterface $search The search.
469
     * @return DataTablesColumn Returns this column.
470
     */
471
    public function setSearch(DataTablesSearchInterface $search) {
472
        $this->search = $search;
473
        return $this;
474
    }
475
476
    /**
477
     * Set the searchable.
478
     *
479
     * @param bool $searchable The searchable.
480
     * @return DataTablesColumn Returns this column.
481
     */
482
    public function setSearchable($searchable) {
483
        $this->searchable = $searchable;
484
        return $this;
485
    }
486
487
    /**
488
     * Set the title.
489
     *
490
     * @param string $title The title.
491
     * @return DataTablesColumn Returns this column.
492
     */
493
    public function setTitle($title) {
494
        $this->title = $title;
495
        return $this;
496
    }
497
498
    /**
499
     * Set the type.
500
     *
501
     * @param string $type The type.
502
     * @return DataTablesColumn Returns this column.
503
     */
504
    public function setType($type) {
505
        if (false === in_array($type, DataTablesColumnHelper::dtTypes())) {
506
            $type = null;
507
        }
508
        $this->type = $type;
509
        return $this;
510
    }
511
512
    /**
513
     * Set the visible.
514
     *
515
     * @param bool $visible The visible.
516
     * @return DataTablesColumn Returns this column.
517
     */
518
    public function setVisible($visible) {
519
        $this->visible = $visible;
520
        return $this;
521
    }
522
523
    /**
524
     * Set the width.
525
     *
526
     * @param string $width The width.
527
     * @return DataTablesColumn Returns this column.
528
     */
529
    public function setWidth($width) {
530
        $this->width = $width;
531
        return $this;
532
    }
533
534
    /**
535
     * Convert into an array representing this instance.
536
     *
537
     * @return array Returns an array representing this instance.
538
     */
539
    public function toArray() {
540
541
        // Initialize the output.
542
        $output = [];
543
544
        ArrayHelper::set($output, "cellType", $this->cellType, [null]);
545
        ArrayHelper::set($output, "classname", $this->classname, [null]);
546
        ArrayHelper::set($output, "contentPadding", $this->contentPadding, [null]);
547
        ArrayHelper::set($output, "data", $this->data, [null]);
548
        ArrayHelper::set($output, "defaultContent", $this->defaultContent, [null]);
549
        ArrayHelper::set($output, "name", $this->name, [null]);
550
        ArrayHelper::set($output, "orderable", $this->orderable, [null, true]);
551
        ArrayHelper::set($output, "orderData", $this->orderData, [null]);
552
        ArrayHelper::set($output, "orderDataType", $this->orderDataType, [null]);
553
        ArrayHelper::set($output, "orderSequence", $this->orderSequence, [null]);
554
        ArrayHelper::set($output, "searchable", $this->searchable, [null, true]);
555
        ArrayHelper::set($output, "type", $this->type, [null]);
556
        ArrayHelper::set($output, "visible", $this->visible, [null, true]);
557
        ArrayHelper::set($output, "width", $this->width, [null]);
558
559
        // Return the output.
560
        return $output;
561
    }
562
563
}
564