|
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\Helper; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesWrapper; |
|
15
|
|
|
use WBW\Library\Core\Utility\Argument\StringUtility; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* DataTables helper. |
|
19
|
|
|
* |
|
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
21
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Helper |
|
22
|
|
|
*/ |
|
23
|
|
|
class DataTablesHelper { |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Get a DataTables name. |
|
27
|
|
|
* |
|
28
|
|
|
* @param DataTablesWrapper $dtWrapper The wrapper. |
|
29
|
|
|
* @return string Returns the DataTables name. |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function getName(DataTablesWrapper $dtWrapper) { |
|
32
|
|
|
return "dt" . preg_replace("/[^A-Za-z0-9]/", "", $dtWrapper->getName()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Get a DataTables options. |
|
37
|
|
|
* |
|
38
|
|
|
* @param DataTablesWrapper $dtWrapper The wrapper. |
|
39
|
|
|
* @return array Returns the DataTables options. |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function getOptions(DataTablesWrapper $dtWrapper) { |
|
42
|
|
|
|
|
43
|
|
|
// Initialize the output. |
|
44
|
|
|
$output = []; |
|
45
|
|
|
|
|
46
|
|
|
$output["ajax"] = []; |
|
47
|
|
|
$output["ajax"]["method"] = $dtWrapper->getMethod(); |
|
48
|
|
|
$output["ajax"]["url"] = $dtWrapper->getUrl(); |
|
49
|
|
|
$output["columns"] = []; |
|
50
|
|
|
foreach ($dtWrapper->getColumns() as $current) { |
|
51
|
|
|
$output["columns"][] = $current->toArray(); |
|
52
|
|
|
} |
|
53
|
|
|
$output["order"] = []; |
|
54
|
|
|
foreach ($dtWrapper->getOrder() as $current) { |
|
55
|
|
|
$output["order"][] = $current->toArray(); |
|
56
|
|
|
} |
|
57
|
|
|
$output["processing"] = StringUtility::parseBoolean($dtWrapper->getProcessing()); |
|
58
|
|
|
$output["serverSide"] = StringUtility::parseBoolean($dtWrapper->getServerSide()); |
|
59
|
|
|
|
|
60
|
|
|
// Return the output. |
|
61
|
|
|
return $output; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|