1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
6
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
7
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\Finder; |
8
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\EntityUtils; |
9
|
|
|
use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella; |
10
|
|
|
use Symfony\Component\Asset\Packages; |
11
|
|
|
|
12
|
|
|
trait FiCoreControllerTrait |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Lists all tables entities. |
16
|
|
|
*/ |
17
|
7 |
|
public function index(Request $request, Packages $assetsmanager) |
18
|
|
|
{ |
19
|
7 |
|
$bundle = $this->getBundle(); |
|
|
|
|
20
|
7 |
|
$controller = $this->getController(); |
|
|
|
|
21
|
7 |
|
$idpassato = $request->get('id'); |
|
|
|
|
22
|
|
|
|
23
|
7 |
|
if (!$this->getPermessi()->canRead()) { |
|
|
|
|
24
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
|
|
|
|
25
|
|
|
} |
26
|
6 |
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName()); |
27
|
|
|
|
28
|
6 |
|
$entityclassnotation = $this->getEntityClassNotation(); |
29
|
6 |
|
$entityclass = $this->getEntityClassName(); |
|
|
|
|
30
|
|
|
|
31
|
6 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
32
|
|
|
|
33
|
|
|
$modellocolonne = array( |
34
|
|
|
/* |
|
|
|
|
35
|
|
|
$controller . ".nominativo" => array( |
36
|
|
|
"nometabella" => $controller, |
37
|
|
|
"nomecampo" => "nominativo", |
38
|
|
|
"etichetta" => "Nominativo", |
39
|
|
|
"ordine" => 10, |
40
|
|
|
"larghezza" => 200, |
41
|
|
|
"escluso" => false |
42
|
|
|
), |
43
|
|
|
$controller . ".datanascita" => array( |
44
|
|
|
"nometabella" => $controller, |
45
|
|
|
"nomecampo" => "datanascita", |
46
|
|
|
"etichetta" => "Data di nascita", |
47
|
|
|
"ordine" => 20, |
48
|
|
|
"larghezza" => 100, |
49
|
|
|
"escluso" => false |
50
|
|
|
), |
51
|
|
|
|
52
|
|
|
*/ |
53
|
6 |
|
); |
54
|
|
|
|
55
|
6 |
|
$filtri = array(); |
|
|
|
|
56
|
6 |
|
$prefiltri = array(); |
|
|
|
|
57
|
6 |
|
$entityutils = new \Cdf\BiCoreBundle\Utils\Entity\EntityUtils($this->get("doctrine")->getManager()); |
|
|
|
|
58
|
6 |
|
$tablenamefromentity = $entityutils->getTableFromEntity($entityclass); |
59
|
6 |
|
$colonneordinamento = array($tablenamefromentity . '.id' => "DESC"); |
|
|
|
|
60
|
6 |
|
$parametritabella = array("em" => ParametriTabella::setParameter("default"), |
|
|
|
|
61
|
6 |
|
'tablename' => ParametriTabella::setParameter($tablenamefromentity), |
62
|
6 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
63
|
6 |
|
'bundle' => ParametriTabella::setParameter($bundle), |
64
|
6 |
|
'entityname' => ParametriTabella::setParameter($entityclassnotation), |
65
|
6 |
|
'entityclass' => ParametriTabella::setParameter($entityclass), |
66
|
6 |
|
'formclass' => ParametriTabella::setParameter($formclass), |
67
|
6 |
|
'modellocolonne' => ParametriTabella::setParameter(json_encode($modellocolonne)), |
68
|
6 |
|
'permessi' => ParametriTabella::setParameter(json_encode($this->getPermessi())), |
69
|
6 |
|
'urltabella' => ParametriTabella::setParameter($assetsmanager->getUrl('/') . $controller . '/' . 'tabella'), |
70
|
6 |
|
'baseurl' => ParametriTabella::setParameter($assetsmanager->getUrl('/')), |
71
|
6 |
|
'idpassato' => ParametriTabella::setParameter($idpassato), |
72
|
6 |
|
'titolotabella' => ParametriTabella::setParameter("Elenco " . $controller), |
|
|
|
|
73
|
6 |
|
'multiselezione' => ParametriTabella::setParameter("0"), |
|
|
|
|
74
|
6 |
|
'editinline' => ParametriTabella::setParameter("0"), |
|
|
|
|
75
|
6 |
|
'paginacorrente' => ParametriTabella::setParameter("1"), |
|
|
|
|
76
|
6 |
|
'paginetotali' => ParametriTabella::setParameter(""), |
|
|
|
|
77
|
6 |
|
'righetotali' => ParametriTabella::setParameter("0"), |
|
|
|
|
78
|
6 |
|
'righeperpagina' => ParametriTabella::setParameter("15"), |
|
|
|
|
79
|
6 |
|
'estraituttirecords' => ParametriTabella::setParameter("0"), |
|
|
|
|
80
|
6 |
|
'colonneordinamento' => ParametriTabella::setParameter(json_encode($colonneordinamento)), |
81
|
6 |
|
'filtri' => ParametriTabella::setParameter(json_encode($filtri)), |
82
|
6 |
|
'prefiltri' => ParametriTabella::setParameter(json_encode($prefiltri)), |
83
|
6 |
|
'traduzionefiltri' => ParametriTabella::setParameter(""), |
|
|
|
|
84
|
|
|
); |
85
|
|
|
|
86
|
6 |
|
return $this->render($crudtemplate, array('parametritabella' => $parametritabella,)); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
/** |
89
|
|
|
* Lists all tables entities. |
90
|
|
|
*/ |
91
|
1 |
|
public function indexDettaglio(Request $request, Packages $assetsmanager) |
92
|
|
|
{ |
93
|
1 |
|
if (!$this->getPermessi()->canRead()) { |
94
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
98
|
1 |
|
$controller = $this->getController(); |
|
|
|
|
99
|
1 |
|
$parametripassati = json_decode($request->get('parametripassati'), true); |
100
|
|
|
|
101
|
1 |
|
$filtri = $this->getParametroIndexDettaglio($parametripassati, "filtri", array()); |
|
|
|
|
102
|
1 |
|
$prefiltri = $this->getParametroIndexDettaglio($parametripassati, "prefiltri", array()); |
|
|
|
|
103
|
1 |
|
$titolotabella = $this->getParametroIndexDettaglio($parametripassati, "titolotabella", "Elenco " . $controller); |
|
|
|
|
104
|
1 |
|
$modellocolonne = $this->getParametroIndexDettaglio($parametripassati, "modellocolonne", array()); |
|
|
|
|
105
|
1 |
|
$colonneordinamento = $this->getParametroIndexDettaglio($parametripassati, "colonneordinamento", array()); |
|
|
|
|
106
|
1 |
|
$multiselezione = $this->getParametroIndexDettaglio($parametripassati, "multiselezione", 0); |
|
|
|
|
107
|
1 |
|
$parametriform = $this->getParametroIndexDettaglio($parametripassati, "parametriform", array()); |
|
|
|
|
108
|
|
|
|
109
|
1 |
|
$template = $bundle . ':' . $controller . ':' . $this->getThisFunctionName() . '.html.twig'; |
110
|
1 |
|
if (!$this->get('templating')->exists($template)) { |
111
|
1 |
|
$template = $controller . '/Crud/' . $this->getThisFunctionName() . '.html.twig'; |
112
|
|
|
} |
113
|
|
|
|
114
|
1 |
|
$entityclassnotation = $this->getEntityClassNotation(); |
115
|
1 |
|
$entityclass = $this->getEntityClassName(); |
|
|
|
|
116
|
|
|
|
117
|
1 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
118
|
|
|
|
119
|
1 |
|
$entityutils = new \Cdf\BiCoreBundle\Utils\Entity\EntityUtils($this->get("doctrine")->getManager()); |
|
|
|
|
120
|
|
|
|
121
|
1 |
|
$tablenamefromentity = $entityutils->getTableFromEntity($entityclass); |
122
|
1 |
|
$parametritabella = array("em" => ParametriTabella::setParameter("default"), |
|
|
|
|
123
|
1 |
|
'tablename' => ParametriTabella::setParameter($tablenamefromentity), |
124
|
1 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
125
|
1 |
|
'bundle' => ParametriTabella::setParameter($bundle), |
126
|
1 |
|
'entityname' => ParametriTabella::setParameter($entityclassnotation), |
127
|
1 |
|
'entityclass' => ParametriTabella::setParameter($entityclass), |
128
|
1 |
|
'formclass' => ParametriTabella::setParameter($formclass), |
129
|
1 |
|
'parametriform' => ParametriTabella::setParameter(json_encode($parametriform)), |
130
|
1 |
|
'modellocolonne' => ParametriTabella::setParameter(json_encode($modellocolonne)), |
131
|
1 |
|
'permessi' => ParametriTabella::setParameter(json_encode($this->getPermessi())), |
132
|
1 |
|
'urltabella' => ParametriTabella::setParameter($assetsmanager->getUrl('/') . $controller . '/' . 'tabella'), |
133
|
1 |
|
'baseurl' => ParametriTabella::setParameter($assetsmanager->getUrl('/')), |
134
|
1 |
|
'idpassato' => ParametriTabella::setParameter(0), |
135
|
1 |
|
'titolotabella' => ParametriTabella::setParameter($titolotabella), |
136
|
1 |
|
'multiselezione' => ParametriTabella::setParameter($multiselezione), |
137
|
1 |
|
'editinline' => ParametriTabella::setParameter("1"), |
|
|
|
|
138
|
1 |
|
'paginacorrente' => ParametriTabella::setParameter("1"), |
|
|
|
|
139
|
1 |
|
'paginetotali' => ParametriTabella::setParameter(""), |
|
|
|
|
140
|
1 |
|
'righeperpagina' => ParametriTabella::setParameter("15"), |
|
|
|
|
141
|
1 |
|
'colonneordinamento' => ParametriTabella::setParameter(json_encode($colonneordinamento)), |
142
|
1 |
|
'filtri' => ParametriTabella::setParameter(json_encode($filtri)), |
143
|
1 |
|
'prefiltri' => ParametriTabella::setParameter(json_encode($prefiltri)), |
144
|
1 |
|
'traduzionefiltri' => ParametriTabella::setParameter(""), |
|
|
|
|
145
|
|
|
); |
146
|
|
|
|
147
|
1 |
|
return $this->render( |
148
|
1 |
|
$template, |
149
|
|
|
array( |
150
|
1 |
|
'parametritabella' => $parametritabella, |
151
|
|
|
) |
152
|
|
|
); |
153
|
|
|
} |
154
|
1 |
|
private function getParametroIndexDettaglio($parametripassati, $keyparametro, $defaultvalue) |
155
|
|
|
{ |
156
|
1 |
|
if (isset($parametripassati[$keyparametro])) { |
157
|
|
|
$parametro = $parametripassati[$keyparametro]; |
158
|
|
|
} else { |
159
|
1 |
|
$parametro = $defaultvalue; |
160
|
|
|
} |
161
|
1 |
|
return $parametro; |
162
|
|
|
} |
163
|
|
|
|
164
|
7 |
|
protected function getTabellaTemplate($controller) |
165
|
|
|
{ |
166
|
7 |
|
$tabellatemplate = $controller . '/Tabella/tabellaform.html.twig'; |
167
|
7 |
|
if (!$this->get('templating')->exists($tabellatemplate)) { |
168
|
6 |
|
$tabellatemplate = 'BiCoreBundle:' . $controller . ':Tabella/tabellaform.html.twig'; |
169
|
6 |
|
if (!$this->get('templating')->exists($tabellatemplate)) { |
170
|
5 |
|
$tabellatemplate = 'BiCoreBundle:Standard:Tabella/tabellaform.html.twig'; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
7 |
|
return $tabellatemplate; |
175
|
|
|
} |
176
|
10 |
|
protected function getCrudTemplate($bundle, $controller, $operation) |
177
|
|
|
{ |
178
|
10 |
|
$crudtemplate = $bundle . ':' . $controller . ':Crud/' . $operation . '.html.twig'; |
179
|
10 |
|
if (!$this->get('templating')->exists($crudtemplate)) { |
180
|
3 |
|
$crudtemplate = $controller . '/Crud/' . $operation . '.html.twig'; |
181
|
3 |
|
if (!$this->get('templating')->exists($crudtemplate)) { |
182
|
|
|
$crudtemplate = 'BiCoreBundle:Standard:Crud/' . $operation . '.html.twig'; |
183
|
|
|
} |
184
|
|
|
} |
185
|
10 |
|
return $crudtemplate; |
186
|
|
|
} |
187
|
|
|
/** |
188
|
|
|
* Returns the calling function through a backtrace |
189
|
|
|
*/ |
190
|
11 |
|
protected function getThisFunctionName() |
191
|
|
|
{ |
192
|
|
|
// a funciton x has called a function y which called this |
193
|
|
|
// see stackoverflow.com/questions/190421 |
194
|
11 |
|
$caller = debug_backtrace(); |
195
|
11 |
|
$caller = $caller[1]; |
196
|
11 |
|
return $caller['function']; |
197
|
|
|
} |
198
|
11 |
|
protected function getEntityClassNotation() |
199
|
|
|
{ |
200
|
11 |
|
$em = $this->get("doctrine")->getManager(); |
|
|
|
|
201
|
11 |
|
$entityutils = new EntityUtils($em); |
202
|
11 |
|
return $entityutils->getClassNameToShortcutNotations($this->getEntityClassName()); |
203
|
|
|
} |
204
|
14 |
|
protected function getEntityClassName() |
205
|
|
|
{ |
206
|
14 |
|
$em = $this->get("doctrine")->getManager(); |
|
|
|
|
207
|
14 |
|
$entityfinder = new Finder($em, $this->controller); |
208
|
14 |
|
return $entityfinder->getClassNameFromEntityName(); |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|