Completed
Push — master ( b639a7...b026d2 )
by WEBEWEB
08:50
created

DataTablesHelper::getName()   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 1
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