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_SimpleFunction; |
16
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\RendererTwigExtension; |
17
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesWrapperInterface; |
18
|
|
|
use WBW\Library\Core\Argument\ArrayHelper; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* DataTables Twig extension. |
22
|
|
|
* |
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
24
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Twig\Extension |
25
|
|
|
*/ |
26
|
|
|
class DataTablesTwigExtension extends AbstractDataTablesTwigExtension { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Service name. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
const SERVICE_NAME = "webeweb.jquerydatatables.twig.extension"; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructor. |
37
|
|
|
* |
38
|
|
|
* @param Twig_Environment $twigEnvironment The Twig environment. |
39
|
|
|
* @param RendererTwigExtension $rendererTwigExtension The renderer Twig extension. |
40
|
|
|
*/ |
41
|
|
|
public function __construct(Twig_Environment $twigEnvironment, RendererTwigExtension $rendererTwigExtension) { |
42
|
|
|
parent::__construct($twigEnvironment, $rendererTwigExtension); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the Twig functions. |
47
|
|
|
* |
48
|
|
|
* @return array Returns the Twig functions. |
49
|
|
|
*/ |
50
|
|
|
public function getFunctions() { |
51
|
|
|
return [ |
52
|
|
|
new Twig_SimpleFunction("jQueryDataTables", [$this, "jQueryDataTablesFunction"], ["is_safe" => ["html"]]), |
53
|
|
|
new Twig_SimpleFunction("jQueryDataTablesStandalone", [$this, "jQueryDataTablesStandaloneFunction"], ["is_safe" => ["html"]]), |
54
|
|
|
new Twig_SimpleFunction("renderDataTables", [$this, "renderDataTablesFunction"], ["is_safe" => ["html"]]), |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Displays a jQuery DataTables. |
60
|
|
|
* |
61
|
|
|
* @param DataTablesWrapperInterface $dtWrapper The wrapper. |
62
|
|
|
* @param array $args The arguments. |
63
|
|
|
* @return string Returns the jQuery DataTables. |
64
|
|
|
*/ |
65
|
|
|
public function jQueryDataTablesFunction(DataTablesWrapperInterface $dtWrapper, array $args = []) { |
66
|
|
|
return $this->jQueryDataTables($dtWrapper, ArrayHelper::get($args, "selector"), ArrayHelper::get($args, "language")); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Displays a jQuery DataTables "Standalone". |
71
|
|
|
* |
72
|
|
|
* @param array $args The arguments. |
73
|
|
|
* @return string Returns the jQuery DataTables "Standalone". |
74
|
|
|
*/ |
75
|
|
|
public function jQueryDataTablesStandaloneFunction(array $args = []) { |
76
|
|
|
return $this->jQueryDataTablesStandalone(ArrayHelper::get($args, "selector", ".table"), ArrayHelper::get($args, "language"), ArrayHelper::get($args, "options", [])); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Render a DataTables. |
81
|
|
|
* |
82
|
|
|
* @param DataTablesWrapperInterface $dtWrapper The wrapper. |
83
|
|
|
* @param array $args The arguments. |
84
|
|
|
* @return string Returns the rendered DataTables. |
85
|
|
|
*/ |
86
|
|
|
public function renderDataTablesFunction(DataTablesWrapperInterface $dtWrapper, array $args = []) { |
87
|
|
|
return $this->renderDataTables($dtWrapper, ArrayHelper::get($args, "class"), ArrayHelper::get($args, "thead", true), ArrayHelper::get($args, "tfoot", true)); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|