Completed
Push — master ( 47e731...bb8380 )
by WEBEWEB
01:25
created

jQueryDataTablesNameFunction()   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 Symfony\Component\Filesystem\Exception\FileNotFoundException;
15
use Twig\TwigFilter;
16
use Twig\TwigFunction;
17
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesWrapperInterface;
18
use WBW\Bundle\JQuery\DataTablesBundle\Helper\DataTablesWrapperHelper;
19
use WBW\Library\Core\Argument\Helper\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 = "wbw.jquery.datatables.twig.extension";
35
36
    /**
37
     * Get the Twig filters.
38
     *
39
     * @return TwigFilter[] Returns the Twig filters.
40
     */
41
    public function getFilters() {
42
        return [
43
            new TwigFilter("jQueryDataTablesName", [$this, "jQueryDataTablesNameFunction"], ["is_safe" => ["html"]]),
44
            new TwigFilter("jQueryDTName", [$this, "jQueryDataTablesNameFunction"], ["is_safe" => ["html"]]),
45
        ];
46
    }
47
48
    /**
49
     * Get the Twig functions.
50
     *
51
     * @return TwigFunction[] Returns the Twig functions.
52
     */
53
    public function getFunctions() {
54
        return [
55
            new TwigFunction("jQueryDataTables", [$this, "jQueryDataTablesFunction"], ["is_safe" => ["html"]]),
56
            new TwigFunction("jQueryDT", [$this, "jQueryDataTablesFunction"], ["is_safe" => ["html"]]),
57
58
            new TwigFunction("jQueryDataTablesName", [$this, "jQueryDataTablesNameFunction"], ["is_safe" => ["html"]]),
59
            new TwigFunction("jQueryDTName", [$this, "jQueryDataTablesNameFunction"], ["is_safe" => ["html"]]),
60
61
            new TwigFunction("jQueryDataTablesOptions", [$this, "jQueryDataTablesOptionsFunction"], ["is_safe" => ["html"]]),
62
            new TwigFunction("jQueryDTOptions", [$this, "jQueryDataTablesOptionsFunction"], ["is_safe" => ["html"]]),
63
64
            new TwigFunction("jQueryDataTablesStandalone", [$this, "jQueryDataTablesStandaloneFunction"], ["is_safe" => ["html"]]),
65
            new TwigFunction("jQueryDTStandalone", [$this, "jQueryDataTablesStandaloneFunction"], ["is_safe" => ["html"]]),
66
67
            new TwigFunction("renderDataTables", [$this, "renderDataTablesFunction"], ["is_safe" => ["html"]]),
68
            new TwigFunction("renderDT", [$this, "renderDataTablesFunction"], ["is_safe" => ["html"]]),
69
        ];
70
    }
71
72
    /**
73
     * Displays a jQuery DataTables.
74
     *
75
     * @param DataTablesWrapperInterface $dtWrapper The wrapper.
76
     * @param array $args The arguments.
77
     * @return string Returns the jQuery DataTables.
78
     * @throws FileNotFoundException Throws a file not found exception if the language file does not exist.
79
     */
80
    public function jQueryDataTablesFunction(DataTablesWrapperInterface $dtWrapper, array $args = []) {
81
        return $this->jQueryDataTables($dtWrapper, ArrayHelper::get($args, "selector"), ArrayHelper::get($args, "language"));
82
    }
83
84
    /**
85
     * Displays a jQuery DataTables name.
86
     *
87
     * @param DataTablesWrapperInterface $dtWrapper The wrapper.
88
     * @return string Returns the jQuery DataTables name.
89
     */
90
    public function jQueryDataTablesNameFunction(DataTablesWrapperInterface $dtWrapper) {
91
        return DataTablesWrapperHelper::getName($dtWrapper);
92
    }
93
94
    /**
95
     * Displays a jQuery DataTables options.
96
     *
97
     * @param DataTablesWrapperInterface $dtWrapper The wrapper.
98
     * @return array Returns the jQuery DataTables options.
99
     */
100
    public function jQueryDataTablesOptionsFunction(DataTablesWrapperInterface $dtWrapper) {
101
        return DataTablesWrapperHelper::getOptions($dtWrapper);
102
    }
103
104
    /**
105
     * Displays a jQuery DataTables "Standalone".
106
     *
107
     * @param array $args The arguments.
108
     * @return string Returns the jQuery DataTables "Standalone".
109
     * @throws FileNotFoundException Throws a file not found exception if the language file does not exist.
110
     */
111
    public function jQueryDataTablesStandaloneFunction(array $args = []) {
112
        return $this->jQueryDataTablesStandalone(ArrayHelper::get($args, "selector", ".table"), ArrayHelper::get($args, "language"), ArrayHelper::get($args, "options", []));
113
    }
114
115
    /**
116
     * Render a DataTables.
117
     *
118
     * @param DataTablesWrapperInterface $dtWrapper The wrapper.
119
     * @param array $args The arguments.
120
     * @return string Returns the rendered DataTables.
121
     */
122
    public function renderDataTablesFunction(DataTablesWrapperInterface $dtWrapper, array $args = []) {
123
        return $this->renderDataTables($dtWrapper, ArrayHelper::get($args, "class"), ArrayHelper::get($args, "thead", true), ArrayHelper::get($args, "tfoot", true));
124
    }
125
}
126