Completed
Push — master ( 351afc...db9440 )
by WEBEWEB
01:57
created

jQueryDataTablesStandaloneFunction()   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\Twig\Extension;
13
14
use Twig_SimpleFunction;
15
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesWrapper;
16
use WBW\Library\Core\Helper\Argument\ArrayHelper;
17
18
/**
19
 * DataTables Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\JQuery\DataTablesBundle\Twig\Extension
23
 */
24
class DataTablesTwigExtension extends AbstractDataTablesTwigExtension {
25
26
    /**
27
     * Service name.
28
     *
29
     * @var string
30
     */
31
    const SERVICE_NAME = "webeweb.datatablesbundle.twig.extension.datatables";
32
33
    /**
34
     * Constructor.
35
     */
36
    public function __construct() {
37
        parent::__construct();
38
    }
39
40
    /**
41
     * Get the Twig functions.
42
     *
43
     * @return array Returns the Twig functions.
44
     */
45
    public function getFunctions() {
46
        return [
47
            new Twig_SimpleFunction("jQueryDataTables", [$this, "jQueryDataTablesFunction"], ["is_safe" => ["html"]]),
48
            new Twig_SimpleFunction("jQueryDataTablesStandalone", [$this, "jQueryDataTablesStandaloneFunction"], ["is_safe" => ["html"]]),
49
            new Twig_SimpleFunction("renderDataTables", [$this, "renderDataTablesFunction"], ["is_safe" => ["html"]]),
50
        ];
51
    }
52
53
    /**
54
     * Displays a jQuery DataTables.
55
     *
56
     * @param DataTablesWrapper $dtWrapper The wrapper.
57
     * @param array $args The arguments.
58
     * @return string Returns the jQuery DataTables.
59
     */
60
    public function jQueryDataTablesFunction(DataTablesWrapper $dtWrapper, array $args = []) {
61
        return $this->jQueryDataTables($dtWrapper, ArrayHelper::get($args, "selector"), ArrayHelper::get($args, "language", "English"));
62
    }
63
64
    /**
65
     * Displays a jQuery DataTables "Standalone".
66
     *
67
     * @param array $args The arguments.
68
     * @return string Returns the jQuery DataTables "Standalone".
69
     */
70
    public function jQueryDataTablesStandaloneFunction(array $args = []) {
71
        return $this->jQueryDataTablesStandalone(ArrayHelper::get($args, "selector", ".table"), ArrayHelper::get($args, "language", "English"), ArrayHelper::get($args, "options", []));
72
    }
73
74
    /**
75
     * Render a DataTables.
76
     *
77
     * @param DataTablesWrapper $dtWrapper The wrapper.
78
     * @param array $args The arguments.
79
     * @return string Returns the rendered DataTables.
80
     */
81
    public function renderDataTablesFunction(DataTablesWrapper $dtWrapper, array $args = []) {
82
        return $this->renderDataTables($dtWrapper, ArrayHelper::get($args, "class"), ArrayHelper::get($args, "thead", true), ArrayHelper::get($args, "tfoot", true));
83
    }
84
85
}
86