Completed
Push — master ( b026d2...e5ac1d )
by WEBEWEB
01:39
created

DataTablesWrapperHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getOptions() 0 26 3
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 wrapper helper.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\JQuery\DataTablesBundle\Helper
22
 */
23
class DataTablesWrapperHelper {
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
51
        foreach ($dtWrapper->getColumns() as $current) {
52
            $output["columns"][] = $current->toArray();
53
        }
54
55
        $output["order"] = [];
56
57
        foreach ($dtWrapper->getOrder() as $current) {
58
            $output["order"][] = $current->toArray();
59
        }
60
61
        $output["processing"] = StringUtility::parseBoolean($dtWrapper->getProcessing());
62
        $output["serverSide"] = StringUtility::parseBoolean($dtWrapper->getServerSide());
63
64
        // Return the output.
65
        return $output;
66
    }
67
68
}
69