1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the jquery-datatables-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2019 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\Normalizer; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesColumnInterface; |
15
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesResponseInterface; |
16
|
|
|
use WBW\Library\Core\Argument\ArrayHelper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* DataTables normalizer. |
20
|
|
|
* |
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
22
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Normalizer |
23
|
|
|
*/ |
24
|
|
|
class DataTablesNormalizer { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Normalize a column. |
28
|
|
|
* |
29
|
|
|
* @param DataTablesColumnInterface $column The column. |
30
|
|
|
* @return array Returns teh normalized column. |
31
|
|
|
*/ |
32
|
|
|
public static function normalizeColumn(DataTablesColumnInterface $column) { |
33
|
|
|
|
34
|
|
|
$output = []; |
35
|
|
|
|
36
|
|
|
ArrayHelper::set($output, "cellType", $column->getCellType(), [null]); |
37
|
|
|
ArrayHelper::set($output, "classname", $column->getClassname(), [null]); |
38
|
|
|
ArrayHelper::set($output, "contentPadding", $column->getContentPadding(), [null]); |
39
|
|
|
ArrayHelper::set($output, "data", $column->getData(), [null]); |
40
|
|
|
ArrayHelper::set($output, "defaultContent", $column->getDefaultContent(), [null]); |
41
|
|
|
ArrayHelper::set($output, "name", $column->getName(), [null]); |
42
|
|
|
ArrayHelper::set($output, "orderable", $column->getOrderable(), [null, true]); |
43
|
|
|
ArrayHelper::set($output, "orderData", $column->getOrderData(), [null]); |
44
|
|
|
ArrayHelper::set($output, "orderDataType", $column->getOrderDataType(), [null]); |
45
|
|
|
ArrayHelper::set($output, "orderSequence", $column->getOrderSequence(), [null]); |
46
|
|
|
ArrayHelper::set($output, "searchable", $column->getSearchable(), [null, true]); |
47
|
|
|
ArrayHelper::set($output, "type", $column->getType(), [null]); |
48
|
|
|
ArrayHelper::set($output, "visible", $column->getVisible(), [null, true]); |
49
|
|
|
ArrayHelper::set($output, "width", $column->getWidth(), [null]); |
50
|
|
|
|
51
|
|
|
return $output; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Normalize a response. |
56
|
|
|
* |
57
|
|
|
* @param DataTablesResponseInterface $response The response. |
58
|
|
|
* @return array Returns the normalized response. |
59
|
|
|
*/ |
60
|
|
|
public static function normalizeResponse(DataTablesResponseInterface $response) { |
61
|
|
|
|
62
|
|
|
$output = []; |
63
|
|
|
|
64
|
|
|
$output["data"] = $response->getData(); |
65
|
|
|
$output["draw"] = $response->getDraw(); |
66
|
|
|
$output["recordsFiltered"] = $response->getRecordsFiltered(); |
67
|
|
|
$output["recordsTotal"] = $response->getRecordsTotal(); |
68
|
|
|
|
69
|
|
|
return $output; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|