Completed
Push — master ( 32466f...3af233 )
by WEBEWEB
16:24
created

DataTablesColumn::getOrderSequence()   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\Library\Core\Argument\ArrayHelper;
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 DataTablesColumnInterface, JsonSerializable {
24
25
    /**
26
     * Cell type.
27
     *
28
     * @var string
29
     */
30
    private $cellType;
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 DataTablesMappingInterface
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 bool
99
     */
100
    private $orderable;
101
102
    /**
103
     * Search.
104
     *
105
     * @var DataTablesSearchInterface
106
     */
107
    private $search;
108
109
    /**
110
     * Searchable.
111
     *
112
     * @var bool
113
     */
114
    private $searchable;
115
116
    /**
117
     * Title.
118
     *
119
     * @var string
120
     */
121
    private $title;
122
123
    /**
124
     * Type.
125
     *
126
     * @var string
127
     */
128
    private $type;
129
130
    /**
131
     * Visible.
132
     *
133
     * @var bool
134
     */
135
    private $visible;
136
137
    /**
138
     * Width.
139
     *
140
     * @var string
141
     */
142
    private $width;
143
144
    /**
145
     * Constructor.
146
     */
147
    public function __construct() {
148
        $this->setCellType(self::DATATABLES_CELL_TYPE_TD);
149
        $this->setMapping(new DataTablesMapping());
150
        $this->setOrderable(true);
151
        $this->setSearchable(true);
152
        $this->setVisible(true);
153
    }
154
155
    /**
156
     * Get the cell type.
157
     *
158
     * @return string Returns the cell type.
159
     */
160
    public function getCellType() {
161
        return $this->cellType;
162
    }
163
164
    /**
165
     * Get the class name.
166
     *
167
     * @return string Returns the class name.
168
     */
169
    public function getClassname() {
170
        return $this->classname;
171
    }
172
173
    /**
174
     * Get the content padding.
175
     *
176
     * @return string Returns the content padding.
177
     */
178
    public function getContentPadding() {
179
        return $this->contentPadding;
180
    }
181
182
    /**
183
     * Get the data.
184
     *
185
     * @return integer|string Returns the data.
186
     */
187
    public function getData() {
188
        return $this->data;
189
    }
190
191
    /**
192
     * Get the default content
193
     *
194
     * @return string Returns the default content.
195
     */
196
    public function getDefaultContent() {
197
        return $this->defaultContent;
198
    }
199
200
    /**
201
     * Get the mapping.
202
     *
203
     * @return DataTablesMappingInterface The mapping.
204
     */
205
    public function getMapping() {
206
        return $this->mapping;
207
    }
208
209
    /**
210
     * Get the name.
211
     *
212
     * @return string Returns the name.
213
     */
214
    public function getName() {
215
        return $this->name;
216
    }
217
218
    /**
219
     * Get the order data.
220
     *
221
     * @return integer|array Returns the order data.
222
     */
223
    public function getOrderData() {
224
        return $this->orderData;
225
    }
226
227
    /**
228
     * Get the order data type.
229
     *
230
     * @return string Returns the order data type.
231
     */
232
    public function getOrderDataType() {
233
        return $this->orderDataType;
234
    }
235
236
    /**
237
     * Get the order sequence.
238
     *
239
     * @return string Returns the order sequence.
240
     */
241
    public function getOrderSequence() {
242
        return $this->orderSequence;
243
    }
244
245
    /**
246
     * Get the orderable.
247
     *
248
     * @return bool Returns the orderable.
249
     */
250
    public function getOrderable() {
251
        return $this->orderable;
252
    }
253
254
    /**
255
     * Get the search.
256
     *
257
     * @return DataTablesSearchInterface Returns the search.
258
     */
259
    public function getSearch() {
260
        return $this->search;
261
    }
262
263
    /**
264
     * Get the searchable.
265
     *
266
     * @return bool Returns the searchable.
267
     */
268
    public function getSearchable() {
269
        return $this->searchable;
270
    }
271
272
    /**
273
     * Get the title.
274
     *
275
     * @return string Returns the title.
276
     */
277
    public function getTitle() {
278
        return $this->title;
279
    }
280
281
    /**
282
     * Get the type.
283
     *
284
     * @return string Returns the type.
285
     */
286
    public function getType() {
287
        return $this->type;
288
    }
289
290
    /**
291
     * Get the visible.
292
     *
293
     * @return bool Returns the visible.
294
     */
295
    public function getVisible() {
296
        return $this->visible;
297
    }
298
299
    /**
300
     * Get the width.
301
     *
302
     * @return string Returns the width.
303
     */
304
    public function getWidth() {
305
        return $this->width;
306
    }
307
308
    /**
309
     * {@inheritdoc}
310
     */
311
    public function jsonSerialize() {
312
        return $this->toArray();
313
    }
314
315
    /**
316
     * Set the cell type.
317
     *
318
     * @param string $cellType The cell type.
319
     * @return DataTablesColumnInterface Returns this column.
320
     */
321
    public function setCellType($cellType) {
322
        if (false === in_array($cellType, DataTablesEnumerator::enumCellTypes())) {
323
            $cellType = self::DATATABLES_CELL_TYPE_TD;
324
        }
325
        $this->cellType = $cellType;
326
        return $this;
327
    }
328
329
    /**
330
     * Set the class name.
331
     *
332
     * @param string $classname The class name.
333
     * @return DataTablesColumnInterface Returns this column.
334
     */
335
    public function setClassname($classname) {
336
        $this->classname = $classname;
337
        return $this;
338
    }
339
340
    /**
341
     * Set the content padding.
342
     *
343
     * @param string $contentPadding The content padding.
344
     * @return DataTablesColumnInterface Returns this column.
345
     */
346
    public function setContentPadding($contentPadding) {
347
        $this->contentPadding = $contentPadding;
348
        return $this;
349
    }
350
351
    /**
352
     * Set the data.
353
     *
354
     * @param integer|string $data The data.
355
     * @return DataTablesColumnInterface Returns this column.
356
     */
357
    public function setData($data) {
358
        $this->data = $data;
359
        return $this;
360
    }
361
362
    /**
363
     * Set the default content.
364
     *
365
     * @param string $defaultContent The default content.
366
     * @return DataTablesColumnInterface Returns this column.
367
     */
368
    public function setDefaultContent($defaultContent) {
369
        $this->defaultContent = $defaultContent;
370
        return $this;
371
    }
372
373
    /**
374
     * Set the mapping.
375
     *
376
     * @param DataTablesMappingInterface $mapping The mapping.
377
     * @return DataTablesColumnInterface Returns this column.
378
     */
379
    protected function setMapping(DataTablesMappingInterface $mapping) {
380
        $this->mapping = $mapping;
381
        return $this;
382
    }
383
384
    /**
385
     * Set the name.
386
     *
387
     * @param string $name The name.
388
     * @return DataTablesColumnInterface Returns this column.
389
     */
390
    public function setName($name) {
391
        $this->name = $name;
392
        return $this;
393
    }
394
395
    /**
396
     * Set the order data.
397
     *
398
     * @param integer|array $orderData The order data.
399
     * @return DataTablesColumnInterface Returns this column.
400
     */
401
    public function setOrderData($orderData) {
402
        $this->orderData = $orderData;
403
        return $this;
404
    }
405
406
    /**
407
     * Set the order data type.
408
     *
409
     * @param string $orderDataType The order data type.
410
     * @return DataTablesColumnInterface Returns this column.
411
     */
412
    public function setOrderDataType($orderDataType) {
413
        $this->orderDataType = $orderDataType;
414
        return $this;
415
    }
416
417
    /**
418
     * Set the order sequence.
419
     *
420
     * @param string $orderSequence The order sequence.
421
     * @return DataTablesColumnInterface Returns this column.
422
     */
423
    public function setOrderSequence($orderSequence) {
424
        if (false === in_array($orderSequence, DataTablesEnumerator::enumOrderSequences())) {
425
            $orderSequence = null;
426
        }
427
        $this->orderSequence = $orderSequence;
428
        return $this;
429
    }
430
431
    /**
432
     * Set the orderable.
433
     *
434
     * @param bool $orderable The orderable.
435
     * @return DataTablesColumnInterface Returns this column.
436
     */
437
    public function setOrderable($orderable) {
438
        $this->orderable = $orderable;
439
        return $this;
440
    }
441
442
    /**
443
     * Set the search.
444
     *
445
     * @param DataTablesSearchInterface $search The search.
446
     * @return DataTablesColumnInterface Returns this column.
447
     */
448
    public function setSearch(DataTablesSearchInterface $search) {
449
        $this->search = $search;
450
        return $this;
451
    }
452
453
    /**
454
     * Set the searchable.
455
     *
456
     * @param bool $searchable The searchable.
457
     * @return DataTablesColumnInterface Returns this column.
458
     */
459
    public function setSearchable($searchable) {
460
        $this->searchable = $searchable;
461
        return $this;
462
    }
463
464
    /**
465
     * Set the title.
466
     *
467
     * @param string $title The title.
468
     * @return DataTablesColumnInterface Returns this column.
469
     */
470
    public function setTitle($title) {
471
        $this->title = $title;
472
        return $this;
473
    }
474
475
    /**
476
     * Set the type.
477
     *
478
     * @param string $type The type.
479
     * @return DataTablesColumnInterface Returns this column.
480
     */
481
    public function setType($type) {
482
        if (false === in_array($type, DataTablesEnumerator::enumTypes())) {
483
            $type = null;
484
        }
485
        $this->type = $type;
486
        return $this;
487
    }
488
489
    /**
490
     * Set the visible.
491
     *
492
     * @param bool $visible The visible.
493
     * @return DataTablesColumnInterface Returns this column.
494
     */
495
    public function setVisible($visible) {
496
        $this->visible = $visible;
497
        return $this;
498
    }
499
500
    /**
501
     * Set the width.
502
     *
503
     * @param string $width The width.
504
     * @return DataTablesColumnInterface Returns this column.
505
     */
506
    public function setWidth($width) {
507
        $this->width = $width;
508
        return $this;
509
    }
510
511
    /**
512
     * Convert into an array representing this instance.
513
     *
514
     * @return array Returns an array representing this instance.
515
     */
516
    public function toArray() {
517
518
        // Initialize the output.
519
        $output = [];
520
521
        ArrayHelper::set($output, "cellType", $this->cellType, [null]);
522
        ArrayHelper::set($output, "classname", $this->classname, [null]);
523
        ArrayHelper::set($output, "contentPadding", $this->contentPadding, [null]);
524
        ArrayHelper::set($output, "data", $this->data, [null]);
525
        ArrayHelper::set($output, "defaultContent", $this->defaultContent, [null]);
526
        ArrayHelper::set($output, "name", $this->name, [null]);
527
        ArrayHelper::set($output, "orderable", $this->orderable, [null, true]);
528
        ArrayHelper::set($output, "orderData", $this->orderData, [null]);
529
        ArrayHelper::set($output, "orderDataType", $this->orderDataType, [null]);
530
        ArrayHelper::set($output, "orderSequence", $this->orderSequence, [null]);
531
        ArrayHelper::set($output, "searchable", $this->searchable, [null, true]);
532
        ArrayHelper::set($output, "type", $this->type, [null]);
533
        ArrayHelper::set($output, "visible", $this->visible, [null, true]);
534
        ArrayHelper::set($output, "width", $this->width, [null]);
535
536
        // Return the output.
537
        return $output;
538
    }
539
540
}
541