Completed
Push — master ( 58cc6c...8c1239 )
by WEBEWEB
01:31
created

DataTablesTwigExtension::getFilters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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