Completed
Push — master ( 53f289...8bbe55 )
by WEBEWEB
01:39
created

renderDataTablesFunction()   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\Utility\Argument\ArrayUtility;
17
use WBW\Library\Core\Utility\Argument\StringUtility;
18
19
/**
20
 * DataTables Twig extension.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\JQuery\DataTablesBundle\Twig\Extension
24
 */
25
class DataTablesTwigExtension extends AbstractDataTablesTwigExtension {
26
27
    /**
28
     * Service name.
29
     *
30
     * @var string
31
     */
32
    const SERVICE_NAME = "webeweb.datatablesbundle.twig.extension.datatables";
33
34
    /**
35
     * Constructor.
36
     */
37
    public function __construct() {
38
        parent::__construct();
39
    }
40
41
    /**
42
     * Get the Twig functions.
43
     *
44
     * @return array Returns the Twig functions.
45
     */
46
    public function getFunctions() {
47
        return [
48
            new Twig_SimpleFunction("jQueryDataTables", [$this, "jQueryDataTablesFunction"], ["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, ArrayUtility::get($args, "selector"), ArrayUtility::get($args, "language", "English"));
62
    }
63
64
    /**
65
     * Render a DataTables.
66
     *
67
     * @param DataTablesWrapper $dtWrapper The wrapper.
68
     * @param array $args The arguments.
69
     * @return string Returns the rendered DataTables.
70
     */
71
    public function renderDataTablesFunction(DataTablesWrapper $dtWrapper, array $args = []) {
72
        return $this->renderDataTables($dtWrapper, ArrayUtility::get($args, "class"), ArrayUtility::get($args, "thead", true), ArrayUtility::get($args, "tfoot", true));
73
    }
74
75
}
76