Completed
Push — master ( edbdaf...4748dc )
by WEBEWEB
01:30
created

jQueryDataTablesFunction()   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 2
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\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.jquerydatatables.twig.extension.datatables";
32
33
    /**
34
     * Get the Twig functions.
35
     *
36
     * @return array Returns the Twig functions.
37
     */
38
    public function getFunctions() {
39
        return [
40
            new Twig_SimpleFunction("jQueryDataTables", [$this, "jQueryDataTablesFunction"], ["is_safe" => ["html"]]),
41
            new Twig_SimpleFunction("jQueryDataTablesStandalone", [$this, "jQueryDataTablesStandaloneFunction"], ["is_safe" => ["html"]]),
42
            new Twig_SimpleFunction("renderDataTables", [$this, "renderDataTablesFunction"], ["is_safe" => ["html"]]),
43
        ];
44
    }
45
46
    /**
47
     * Displays a jQuery DataTables.
48
     *
49
     * @param DataTablesWrapper $dtWrapper The wrapper.
50
     * @param array $args The arguments.
51
     * @return string Returns the jQuery DataTables.
52
     */
53
    public function jQueryDataTablesFunction(DataTablesWrapper $dtWrapper, array $args = []) {
54
        return $this->jQueryDataTables($dtWrapper, ArrayHelper::get($args, "selector"), ArrayHelper::get($args, "language"));
55
    }
56
57
    /**
58
     * Displays a jQuery DataTables "Standalone".
59
     *
60
     * @param array $args The arguments.
61
     * @return string Returns the jQuery DataTables "Standalone".
62
     */
63
    public function jQueryDataTablesStandaloneFunction(array $args = []) {
64
        return $this->jQueryDataTablesStandalone(ArrayHelper::get($args, "selector", ".table"), ArrayHelper::get($args, "language"), ArrayHelper::get($args, "options", []));
65
    }
66
67
    /**
68
     * Render a DataTables.
69
     *
70
     * @param DataTablesWrapper $dtWrapper The wrapper.
71
     * @param array $args The arguments.
72
     * @return string Returns the rendered DataTables.
73
     */
74
    public function renderDataTablesFunction(DataTablesWrapper $dtWrapper, array $args = []) {
75
        return $this->renderDataTables($dtWrapper, ArrayHelper::get($args, "class"), ArrayHelper::get($args, "thead", true), ArrayHelper::get($args, "tfoot", true));
76
    }
77
78
}
79