Completed
Push — master ( f4b735...e40de1 )
by WEBEWEB
01:30
created

DataTablesTwigExtension::__construct()   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 Symfony\Component\Filesystem\Exception\FileNotFoundException;
15
use Twig_SimpleFilter;
16
use Twig_SimpleFunction;
17
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesWrapperInterface;
18
use WBW\Bundle\JQuery\DataTablesBundle\Helper\DataTablesWrapperHelper;
19
use WBW\Library\Core\Argument\ArrayHelper;
20
21
/**
22
 * DataTables Twig extension.
23
 *
24
 * @author webeweb <https://github.com/webeweb/>
25
 * @package WBW\Bundle\JQuery\DataTablesBundle\Twig\Extension
26
 */
27
class DataTablesTwigExtension extends AbstractDataTablesTwigExtension {
28
29
    /**
30
     * Service name.
31
     *
32
     * @var string
33
     */
34
    const SERVICE_NAME = "webeweb.jquery_datatables.twig.extension";
35
36
    /**
37
     * Get the Twig filters.
38
     *
39
     * @return Twig_SimpleFilter[] Returns the Twig filters.
40
     */
41
    public function getFilters() {
42
        return [
43
            new Twig_SimpleFilter("jQueryDataTablesName", [$this, "jQueryDataTablesNameFunction"], ["is_safe" => ["html"]]),
44
            new Twig_SimpleFilter("jQueryDTName", [$this, "jQueryDataTablesNameFunction"], ["is_safe" => ["html"]]),
45
        ];
46
    }
47
48
    /**
49
     * Get the Twig functions.
50
     *
51
     * @return array Returns the Twig functions.
52
     */
53
    public function getFunctions() {
54
        return [
55
            new Twig_SimpleFunction("jQueryDataTables", [$this, "jQueryDataTablesFunction"], ["is_safe" => ["html"]]),
56
            new Twig_SimpleFunction("jQueryDT", [$this, "jQueryDataTablesFunction"], ["is_safe" => ["html"]]),
57
58
            new Twig_SimpleFunction("renderDataTables", [$this, "renderDataTablesFunction"], ["is_safe" => ["html"]]),
59
            new Twig_SimpleFunction("renderDT", [$this, "renderDataTablesFunction"], ["is_safe" => ["html"]]),
60
61
            new Twig_SimpleFunction("jQueryDataTablesStandalone", [$this, "jQueryDataTablesStandaloneFunction"], ["is_safe" => ["html"]]),
62
            new Twig_SimpleFunction("jQueryDTStandalone", [$this, "jQueryDataTablesStandaloneFunction"], ["is_safe" => ["html"]]),
63
64
            new Twig_SimpleFunction("jQueryDataTablesName", [$this, "jQueryDataTablesNameFunction"], ["is_safe" => ["html"]]),
65
            new Twig_SimpleFunction("jQueryDTName", [$this, "jQueryDataTablesNameFunction"], ["is_safe" => ["html"]]),
66
        ];
67
    }
68
69
    /**
70
     * Displays a jQuery DataTables.
71
     *
72
     * @param DataTablesWrapperInterface $dtWrapper The wrapper.
73
     * @param array $args The arguments.
74
     * @return string Returns the jQuery DataTables.
75
     * @throws FileNotFoundException Throws a file not found exception if the language file does not exist.
76
     */
77
    public function jQueryDataTablesFunction(DataTablesWrapperInterface $dtWrapper, array $args = []) {
78
        return $this->jQueryDataTables($dtWrapper, ArrayHelper::get($args, "selector"), ArrayHelper::get($args, "language"));
79
    }
80
81
    /**
82
     * Displays a jQuery DataTables name.
83
     *
84
     * @param DataTablesWrapperInterface $dtWrapper The wrapper.
85
     * @return string Returns the jQuery DataTables name.
86
     */
87
    public function jQueryDataTablesNameFunction(DataTablesWrapperInterface $dtWrapper) {
88
        return DataTablesWrapperHelper::getName($dtWrapper);
89
    }
90
91
    /**
92
     * Displays a jQuery DataTables "Standalone".
93
     *
94
     * @param array $args The arguments.
95
     * @return string Returns the jQuery DataTables "Standalone".
96
     * @throws FileNotFoundException Throws a file not found exception if the language file does not exist.
97
     */
98
    public function jQueryDataTablesStandaloneFunction(array $args = []) {
99
        return $this->jQueryDataTablesStandalone(ArrayHelper::get($args, "selector", ".table"), ArrayHelper::get($args, "language"), ArrayHelper::get($args, "options", []));
100
    }
101
102
    /**
103
     * Render a DataTables.
104
     *
105
     * @param DataTablesWrapperInterface $dtWrapper The wrapper.
106
     * @param array $args The arguments.
107
     * @return string Returns the rendered DataTables.
108
     */
109
    public function renderDataTablesFunction(DataTablesWrapperInterface $dtWrapper, array $args = []) {
110
        return $this->renderDataTables($dtWrapper, ArrayHelper::get($args, "class"), ArrayHelper::get($args, "thead", true), ArrayHelper::get($args, "tfoot", true));
111
    }
112
}
113