|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\GridBundle\Grid\Renderer; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
6
|
|
|
use Twig\Environment; |
|
7
|
|
|
|
|
8
|
|
|
class RendererFactory |
|
9
|
|
|
{ |
|
10
|
|
|
protected $twig; |
|
11
|
|
|
protected $router; |
|
12
|
|
|
protected $translator; |
|
13
|
|
|
protected $themeCss; |
|
14
|
|
|
protected $themeJs; |
|
15
|
|
|
protected $pageDivStyle; |
|
16
|
|
|
protected $jqGridJs; |
|
17
|
|
|
protected $jqGridCss; |
|
18
|
|
|
protected $jqGridOptions; |
|
19
|
|
|
protected $tableOptions; |
|
20
|
|
|
protected $dataTablesCss; |
|
21
|
|
|
protected $dataTablesJs; |
|
22
|
|
|
protected $dataTablesClass; |
|
23
|
|
|
protected $dataTablesOptions; |
|
24
|
|
|
protected $jQuery; |
|
25
|
|
|
protected $purl; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct( |
|
28
|
|
|
RouterInterface $router, |
|
29
|
|
|
$translator, |
|
30
|
|
|
array $config |
|
31
|
|
|
) { |
|
32
|
|
|
$this->router = $router; |
|
33
|
|
|
$this->translator = $translator; |
|
34
|
|
|
$this->themeCss = $config['theme.css']; |
|
35
|
|
|
$this->themeJs = $config['theme.js']; |
|
36
|
|
|
$this->pageDivStyle = $config['page_div_style']; |
|
37
|
|
|
$this->jQuery = $config['jquery']; |
|
38
|
|
|
$this->purl = $config['purl']; |
|
39
|
|
|
$this->dataTablesCss = $config['datatables.css']; |
|
40
|
|
|
$this->dataTablesJs = $config['datatables.js']; |
|
41
|
|
|
$this->dataTablesClass = $config['datatables.class']; |
|
42
|
|
|
$this->dataTablesOptions = $config['datatables.options']; |
|
43
|
|
|
$this->jqGridCss = $config['jq_grid.css']; |
|
44
|
|
|
$this->jqGridJs = $config['jq_grid.js']; |
|
45
|
|
|
$this->jqGridOptions = $config['jq_grid.options']; |
|
46
|
|
|
$this->tableOptions = $config['table.options']; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function setTwigEnvironment(Environment $twig) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->twig = $twig; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getTwigEnvironment() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->twig; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Creates a new renderer of type $type, throws an exception if it's not known how to create a renderer of type $type. |
|
61
|
|
|
* |
|
62
|
|
|
* @param $type |
|
63
|
|
|
* |
|
64
|
|
|
* @return AbstractRenderer |
|
65
|
|
|
* |
|
66
|
|
|
* @throws \Exception |
|
67
|
|
|
*/ |
|
68
|
|
|
public function create($type) |
|
69
|
|
|
{ |
|
70
|
|
|
$twig = $this->getTwigEnvironment(); |
|
71
|
|
|
if (!$twig) { |
|
72
|
|
|
throw new \Exception('Twig Engine not found. Please see https://github.com/mmucklo/DtcGridBundle/README.md for instructions.'); |
|
73
|
|
|
} |
|
74
|
|
|
switch ($type) { |
|
75
|
|
|
case 'datatables': |
|
76
|
|
|
$renderer = new DataTablesRenderer($this->twig, $this->router, $this->translator, $this->dataTablesOptions); |
|
77
|
|
|
break; |
|
78
|
|
|
case 'jq_grid': |
|
79
|
|
|
$renderer = new JQGridRenderer($this->twig, $this->router, $this->translator, $this->jqGridOptions); |
|
80
|
|
|
break; |
|
81
|
|
|
case 'table': |
|
82
|
|
|
$renderer = new TableGridRenderer($this->twig, $this->router, $this->translator, $this->tableOptions); |
|
83
|
|
|
break; |
|
84
|
|
|
default: |
|
85
|
|
|
throw new \Exception("No renderer for type '$type''"); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if (method_exists($renderer, 'setThemeCss')) { |
|
89
|
|
|
$renderer->setThemeCss($this->themeCss); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (method_exists($renderer, 'setThemeJs')) { |
|
93
|
|
|
$renderer->setThemeJs($this->themeJs); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if (method_exists($renderer, 'setJQuery')) { |
|
97
|
|
|
$renderer->setJQuery($this->jQuery); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if (method_exists($renderer, 'setPurl')) { |
|
101
|
|
|
$renderer->setPurl($this->purl); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
if (method_exists($renderer, 'setPageDivStyle')) { |
|
105
|
|
|
$renderer->setPageDivStyle($this->pageDivStyle); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if (method_exists($renderer, 'setJqGridCss')) { |
|
109
|
|
|
$renderer->setJqGridCss($this->jqGridCss); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
if (method_exists($renderer, 'setJqGridJs')) { |
|
113
|
|
|
$renderer->setJqGridJs($this->jqGridJs); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
if (method_exists($renderer, 'setDataTablesCss')) { |
|
117
|
|
|
$renderer->setDataTablesCss($this->dataTablesCss); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
if (method_exists($renderer, 'setDataTablesJs')) { |
|
121
|
|
|
$renderer->setDataTablesJs($this->dataTablesJs); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
if (method_exists($renderer, 'setDatatablesClass') && $this->dataTablesClass) { |
|
125
|
|
|
$renderer->setDatatablesClass($this->dataTablesClass); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $renderer; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|