|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
7
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
8
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\Finder; |
|
9
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\EntityUtils; |
|
10
|
|
|
use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella; |
|
11
|
|
|
use Cdf\BiCoreBundle\Utils\Export\TabellaXls; |
|
12
|
|
|
use Cdf\BiCoreBundle\Utils\Tabella\Tabella; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
14
|
|
|
use Symfony\Component\Asset\Packages; |
|
15
|
|
|
|
|
16
|
|
|
trait FiCoreControllerTrait |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Lists all tables entities. |
|
20
|
|
|
*/ |
|
21
|
7 |
|
public function index(Request $request, Packages $assetsmanager) |
|
22
|
|
|
{ |
|
23
|
7 |
|
$bundle = $this->getBundle(); |
|
|
|
|
|
|
24
|
7 |
|
$controller = $this->getController(); |
|
25
|
7 |
|
$idpassato = $request->get('id'); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
7 |
|
if (!$this->getPermessi()->canRead()) { |
|
28
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
6 |
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName()); |
|
31
|
|
|
|
|
32
|
6 |
|
$entityclassnotation = $this->getEntityClassNotation(); |
|
33
|
6 |
|
$entityclass = $this->getEntityClassName(); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
6 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$modellocolonne = array( |
|
38
|
|
|
/* |
|
|
|
|
|
|
39
|
|
|
$controller . ".nominativo" => array( |
|
40
|
|
|
"nometabella" => $controller, |
|
41
|
|
|
"nomecampo" => "nominativo", |
|
42
|
|
|
"etichetta" => "Nominativo", |
|
43
|
|
|
"ordine" => 10, |
|
44
|
|
|
"larghezza" => 200, |
|
45
|
|
|
"escluso" => false |
|
46
|
|
|
), |
|
47
|
|
|
$controller . ".datanascita" => array( |
|
48
|
|
|
"nometabella" => $controller, |
|
49
|
|
|
"nomecampo" => "datanascita", |
|
50
|
|
|
"etichetta" => "Data di nascita", |
|
51
|
|
|
"ordine" => 20, |
|
52
|
|
|
"larghezza" => 100, |
|
53
|
|
|
"escluso" => false |
|
54
|
|
|
), |
|
55
|
|
|
|
|
56
|
|
|
*/ |
|
57
|
6 |
|
); |
|
58
|
|
|
|
|
59
|
6 |
|
$filtri = array(); |
|
|
|
|
|
|
60
|
6 |
|
$prefiltri = array(); |
|
|
|
|
|
|
61
|
6 |
|
$entityutils = new \Cdf\BiCoreBundle\Utils\Entity\EntityUtils($this->get("doctrine")->getManager()); |
|
|
|
|
|
|
62
|
6 |
|
$tablenamefromentity = $entityutils->getTableFromEntity($entityclass); |
|
63
|
6 |
|
$colonneordinamento = array($tablenamefromentity . '.id' => "DESC"); |
|
|
|
|
|
|
64
|
6 |
|
$parametritabella = array("em" => ParametriTabella::setParameter("default"), |
|
|
|
|
|
|
65
|
6 |
|
'tablename' => ParametriTabella::setParameter($tablenamefromentity), |
|
66
|
6 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
|
67
|
6 |
|
'bundle' => ParametriTabella::setParameter($bundle), |
|
68
|
6 |
|
'entityname' => ParametriTabella::setParameter($entityclassnotation), |
|
69
|
6 |
|
'entityclass' => ParametriTabella::setParameter($entityclass), |
|
70
|
6 |
|
'formclass' => ParametriTabella::setParameter($formclass), |
|
71
|
6 |
|
'modellocolonne' => ParametriTabella::setParameter(json_encode($modellocolonne)), |
|
72
|
6 |
|
'permessi' => ParametriTabella::setParameter(json_encode($this->getPermessi())), |
|
73
|
6 |
|
'urltabella' => ParametriTabella::setParameter($assetsmanager->getUrl('/') . $controller . '/' . 'tabella'), |
|
74
|
6 |
|
'baseurl' => ParametriTabella::setParameter($assetsmanager->getUrl('/')), |
|
75
|
6 |
|
'idpassato' => ParametriTabella::setParameter($idpassato), |
|
76
|
6 |
|
'titolotabella' => ParametriTabella::setParameter("Elenco " . $controller), |
|
|
|
|
|
|
77
|
6 |
|
'multiselezione' => ParametriTabella::setParameter("0"), |
|
|
|
|
|
|
78
|
6 |
|
'editinline' => ParametriTabella::setParameter("0"), |
|
|
|
|
|
|
79
|
6 |
|
'paginacorrente' => ParametriTabella::setParameter("1"), |
|
|
|
|
|
|
80
|
6 |
|
'paginetotali' => ParametriTabella::setParameter(""), |
|
|
|
|
|
|
81
|
6 |
|
'righetotali' => ParametriTabella::setParameter("0"), |
|
|
|
|
|
|
82
|
6 |
|
'righeperpagina' => ParametriTabella::setParameter("15"), |
|
|
|
|
|
|
83
|
6 |
|
'estraituttirecords' => ParametriTabella::setParameter("0"), |
|
|
|
|
|
|
84
|
6 |
|
'colonneordinamento' => ParametriTabella::setParameter(json_encode($colonneordinamento)), |
|
85
|
6 |
|
'filtri' => ParametriTabella::setParameter(json_encode($filtri)), |
|
86
|
6 |
|
'prefiltri' => ParametriTabella::setParameter(json_encode($prefiltri)), |
|
87
|
6 |
|
'traduzionefiltri' => ParametriTabella::setParameter(""), |
|
|
|
|
|
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
6 |
|
return $this->render($crudtemplate, array('parametritabella' => $parametritabella,)); |
|
91
|
|
|
} |
|
92
|
|
|
/** |
|
93
|
|
|
* Lists all tables entities. |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function indexDettaglio(Request $request, Packages $assetsmanager) |
|
96
|
|
|
{ |
|
97
|
1 |
|
if (!$this->getPermessi()->canRead()) { |
|
98
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
|
|
102
|
1 |
|
$controller = $this->getController(); |
|
|
|
|
|
|
103
|
1 |
|
$parametripassati = json_decode($request->get('parametripassati'), true); |
|
104
|
|
|
|
|
105
|
1 |
|
$filtri = $this->getParametroIndexDettaglio($parametripassati, "filtri", array()); |
|
|
|
|
|
|
106
|
1 |
|
$prefiltri = $this->getParametroIndexDettaglio($parametripassati, "prefiltri", array()); |
|
|
|
|
|
|
107
|
1 |
|
$titolotabella = $this->getParametroIndexDettaglio($parametripassati, "titolotabella", "Elenco " . $controller); |
|
|
|
|
|
|
108
|
1 |
|
$modellocolonne = $this->getParametroIndexDettaglio($parametripassati, "modellocolonne", array()); |
|
|
|
|
|
|
109
|
1 |
|
$colonneordinamento = $this->getParametroIndexDettaglio($parametripassati, "colonneordinamento", array()); |
|
|
|
|
|
|
110
|
1 |
|
$multiselezione = $this->getParametroIndexDettaglio($parametripassati, "multiselezione", 0); |
|
|
|
|
|
|
111
|
1 |
|
$parametriform = $this->getParametroIndexDettaglio($parametripassati, "parametriform", array()); |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
1 |
|
$template = $bundle . ':' . $controller . ':' . $this->getThisFunctionName() . '.html.twig'; |
|
114
|
1 |
|
if (!$this->get('templating')->exists($template)) { |
|
115
|
1 |
|
$template = $controller . '/Crud/' . $this->getThisFunctionName() . '.html.twig'; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
1 |
|
$entityclassnotation = $this->getEntityClassNotation(); |
|
119
|
1 |
|
$entityclass = $this->getEntityClassName(); |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
1 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
|
|
122
|
|
|
|
|
123
|
1 |
|
$entityutils = new \Cdf\BiCoreBundle\Utils\Entity\EntityUtils($this->get("doctrine")->getManager()); |
|
|
|
|
|
|
124
|
|
|
|
|
125
|
1 |
|
$tablenamefromentity = $entityutils->getTableFromEntity($entityclass); |
|
126
|
1 |
|
$parametritabella = array("em" => ParametriTabella::setParameter("default"), |
|
|
|
|
|
|
127
|
1 |
|
'tablename' => ParametriTabella::setParameter($tablenamefromentity), |
|
128
|
1 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
|
129
|
1 |
|
'bundle' => ParametriTabella::setParameter($bundle), |
|
130
|
1 |
|
'entityname' => ParametriTabella::setParameter($entityclassnotation), |
|
131
|
1 |
|
'entityclass' => ParametriTabella::setParameter($entityclass), |
|
132
|
1 |
|
'formclass' => ParametriTabella::setParameter($formclass), |
|
133
|
1 |
|
'parametriform' => ParametriTabella::setParameter(json_encode($parametriform)), |
|
134
|
1 |
|
'modellocolonne' => ParametriTabella::setParameter(json_encode($modellocolonne)), |
|
135
|
1 |
|
'permessi' => ParametriTabella::setParameter(json_encode($this->getPermessi())), |
|
136
|
1 |
|
'urltabella' => ParametriTabella::setParameter($assetsmanager->getUrl('/') . $controller . '/' . 'tabella'), |
|
137
|
1 |
|
'baseurl' => ParametriTabella::setParameter($assetsmanager->getUrl('/')), |
|
138
|
1 |
|
'idpassato' => ParametriTabella::setParameter(0), |
|
139
|
1 |
|
'titolotabella' => ParametriTabella::setParameter($titolotabella), |
|
140
|
1 |
|
'multiselezione' => ParametriTabella::setParameter($multiselezione), |
|
141
|
1 |
|
'editinline' => ParametriTabella::setParameter("1"), |
|
|
|
|
|
|
142
|
1 |
|
'paginacorrente' => ParametriTabella::setParameter("1"), |
|
|
|
|
|
|
143
|
1 |
|
'paginetotali' => ParametriTabella::setParameter(""), |
|
|
|
|
|
|
144
|
1 |
|
'righeperpagina' => ParametriTabella::setParameter("15"), |
|
|
|
|
|
|
145
|
1 |
|
'colonneordinamento' => ParametriTabella::setParameter(json_encode($colonneordinamento)), |
|
146
|
1 |
|
'filtri' => ParametriTabella::setParameter(json_encode($filtri)), |
|
147
|
1 |
|
'prefiltri' => ParametriTabella::setParameter(json_encode($prefiltri)), |
|
148
|
1 |
|
'traduzionefiltri' => ParametriTabella::setParameter(""), |
|
|
|
|
|
|
149
|
|
|
); |
|
150
|
|
|
|
|
151
|
1 |
|
return $this->render( |
|
152
|
1 |
|
$template, |
|
153
|
|
|
array( |
|
154
|
1 |
|
'parametritabella' => $parametritabella, |
|
155
|
|
|
) |
|
156
|
|
|
); |
|
157
|
|
|
} |
|
158
|
1 |
|
private function getParametroIndexDettaglio($parametripassati, $keyparametro, $defaultvalue) |
|
159
|
|
|
{ |
|
160
|
1 |
|
if (isset($parametripassati[$keyparametro])) { |
|
161
|
|
|
$parametro = $parametripassati[$keyparametro]; |
|
162
|
|
|
} else { |
|
163
|
1 |
|
$parametro = $defaultvalue; |
|
164
|
|
|
} |
|
165
|
1 |
|
return $parametro; |
|
166
|
|
|
} |
|
167
|
|
|
/** |
|
168
|
|
|
* Displays a form to create a new table entity. |
|
169
|
|
|
*/ |
|
170
|
7 |
|
public function new(Request $request) |
|
171
|
|
|
{ |
|
172
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
|
173
|
7 |
|
$bundle = $this->getBundle(); |
|
|
|
|
|
|
174
|
7 |
|
$controller = $this->getController(); |
|
175
|
7 |
|
if (!$this->getPermessi()->canCreate()) { |
|
176
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per creare questo contenuto"); |
|
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
6 |
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName()); |
|
|
|
|
|
|
180
|
6 |
|
$tabellatemplate = $this->getTabellaTemplate($controller); |
|
181
|
|
|
|
|
182
|
6 |
|
$parametriform = $request->get("parametriform") ? json_decode($request->get("parametriform"), true) : array(); |
|
|
|
|
|
|
183
|
|
|
|
|
184
|
6 |
|
$entityclass = $this->getEntityClassName(); |
|
185
|
6 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
|
|
186
|
|
|
|
|
187
|
6 |
|
$entity = new $entityclass(); |
|
|
|
|
|
|
188
|
6 |
|
$formType = $formclass . 'Type'; |
|
189
|
6 |
|
$form = $this->createForm($formType, $entity, array('attr' => array( |
|
|
|
|
|
|
190
|
6 |
|
'id' => 'formdati' . $controller, |
|
191
|
|
|
), |
|
192
|
6 |
|
'action' => $this->generateUrl($controller . '_new'), "parametriform" => $parametriform |
|
|
|
|
|
|
193
|
|
|
)); |
|
194
|
|
|
|
|
195
|
6 |
|
$form->handleRequest($request); |
|
196
|
|
|
|
|
197
|
|
|
$twigparms = array( |
|
198
|
6 |
|
'form' => $form->createView(), |
|
199
|
6 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
|
200
|
6 |
|
'tabellatemplate' => $tabellatemplate |
|
201
|
|
|
); |
|
202
|
|
|
|
|
203
|
6 |
|
if ($form->isSubmitted()) { |
|
204
|
6 |
|
if ($form->isValid()) { |
|
205
|
5 |
|
$entity = $form->getData(); |
|
206
|
|
|
|
|
207
|
5 |
|
$entityManager = $this->getDoctrine()->getManager(); |
|
208
|
5 |
|
$entityManager->persist($entity); |
|
209
|
5 |
|
$entityManager->flush(); |
|
210
|
5 |
|
return new Response( |
|
211
|
5 |
|
$this->renderView($crudtemplate, $twigparms), |
|
212
|
5 |
|
200 |
|
213
|
|
|
); |
|
214
|
|
|
} else { |
|
215
|
|
|
//Quando non passa la validazione |
|
216
|
1 |
|
return new Response( |
|
217
|
1 |
|
$this->renderView($crudtemplate, $twigparms), |
|
218
|
1 |
|
400 |
|
219
|
|
|
); |
|
220
|
|
|
} |
|
221
|
|
|
} else { |
|
222
|
|
|
//Quando viene richiesta una "nuova" new |
|
223
|
6 |
|
return new Response( |
|
224
|
6 |
|
$this->renderView($crudtemplate, $twigparms), |
|
225
|
6 |
|
200 |
|
226
|
|
|
); |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
/** |
|
230
|
|
|
* Displays a form to edit an existing table entity. |
|
231
|
|
|
*/ |
|
232
|
8 |
|
public function edit(Request $request, $id) |
|
233
|
|
|
{ |
|
234
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
|
235
|
8 |
|
$bundle = $this->getBundle(); |
|
|
|
|
|
|
236
|
8 |
|
$controller = $this->getController(); |
|
237
|
|
|
|
|
238
|
8 |
|
if (!$this->getPermessi()->canUpdate()) { |
|
239
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per modificare questo contenuto"); |
|
|
|
|
|
|
240
|
|
|
} |
|
241
|
7 |
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName()); |
|
|
|
|
|
|
242
|
7 |
|
$tabellatemplate = $this->getTabellaTemplate($controller); |
|
243
|
|
|
|
|
244
|
7 |
|
$entityclass = $this->getEntityClassName(); |
|
245
|
7 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
|
|
246
|
|
|
|
|
247
|
7 |
|
$formType = $formclass . 'Type'; |
|
248
|
|
|
|
|
249
|
7 |
|
$elencomodifiche = $this->elencoModifiche($controller, $id); |
|
250
|
|
|
|
|
251
|
7 |
|
$em = $this->getDoctrine()->getManager(); |
|
252
|
|
|
|
|
253
|
7 |
|
$entity = $em->getRepository($entityclass)->find($id); |
|
254
|
|
|
|
|
255
|
7 |
|
if (!$entity) { |
|
256
|
1 |
|
throw $this->createNotFoundException('Impossibile trovare l\'entità ' . $controller . ' del record con id ' . $id . '.'); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
7 |
|
$editForm = $this->createForm( |
|
260
|
7 |
|
$formType, |
|
261
|
7 |
|
$entity, |
|
262
|
|
|
array('attr' => array( |
|
263
|
7 |
|
'id' => 'formdati' . $controller, |
|
264
|
|
|
), |
|
265
|
7 |
|
'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())), |
|
266
|
|
|
) |
|
267
|
|
|
); |
|
268
|
|
|
|
|
269
|
7 |
|
return $this->render( |
|
270
|
7 |
|
$crudtemplate, |
|
271
|
|
|
array( |
|
272
|
7 |
|
'entity' => $entity, |
|
273
|
7 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
|
274
|
7 |
|
'tabellatemplate' => $tabellatemplate, |
|
275
|
7 |
|
'edit_form' => $editForm->createView(), |
|
276
|
7 |
|
'elencomodifiche' => $elencomodifiche, |
|
277
|
|
|
) |
|
278
|
|
|
); |
|
279
|
|
|
} |
|
280
|
|
|
/** |
|
281
|
|
|
* Edits an existing table entity. |
|
282
|
|
|
*/ |
|
283
|
9 |
|
public function update(Request $request, $id) |
|
284
|
|
|
{ |
|
285
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
|
286
|
9 |
|
$bundle = $this->getBundle(); |
|
|
|
|
|
|
287
|
9 |
|
$controller = $this->getController(); |
|
288
|
9 |
|
if (!$this->getPermessi()->canUpdate()) { |
|
289
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per modificare questo contenuto"); |
|
|
|
|
|
|
290
|
|
|
} |
|
291
|
8 |
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, "edit"); |
|
|
|
|
|
|
292
|
|
|
|
|
293
|
8 |
|
$entityclass = $this->getEntityClassName(); |
|
294
|
8 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
|
|
295
|
8 |
|
$formType = $formclass . 'Type'; |
|
|
|
|
|
|
296
|
|
|
|
|
297
|
8 |
|
$em = $this->getDoctrine()->getManager(); |
|
298
|
|
|
|
|
299
|
8 |
|
$entity = $em->getRepository($entityclass)->find($id); |
|
300
|
|
|
|
|
301
|
8 |
|
if (!$entity) { |
|
302
|
1 |
|
throw $this->createNotFoundException('Impossibile trovare l\'entità ' . $controller . ' per il record con id ' . $id); |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
7 |
|
$editForm = $this->createForm( |
|
306
|
7 |
|
$formType, |
|
307
|
7 |
|
$entity, |
|
308
|
|
|
array('attr' => array( |
|
309
|
7 |
|
'id' => 'formdati' . $controller, |
|
310
|
|
|
), |
|
311
|
7 |
|
'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())), |
|
312
|
|
|
) |
|
313
|
|
|
); |
|
314
|
|
|
|
|
315
|
7 |
|
$editForm->submit($request->request->get($editForm->getName())); |
|
316
|
|
|
|
|
317
|
7 |
|
if ($editForm->isValid()) { |
|
318
|
7 |
|
$originalData = $em->getUnitOfWork()->getOriginalEntityData($entity); |
|
319
|
|
|
|
|
320
|
7 |
|
$em->persist($entity); |
|
321
|
7 |
|
$em->flush(); |
|
322
|
|
|
|
|
323
|
7 |
|
$newData = $em->getUnitOfWork()->getOriginalEntityData($entity); |
|
|
|
|
|
|
324
|
7 |
|
$repoStorico = $em->getRepository("BiCoreBundle:Storicomodifiche"); |
|
|
|
|
|
|
325
|
7 |
|
$changes = $repoStorico->isRecordChanged($controller, $originalData, $newData); |
|
|
|
|
|
|
326
|
|
|
|
|
327
|
7 |
|
if ($changes) { |
|
328
|
2 |
|
$repoStorico->saveHistory($controller, $changes, $id, $this->getUser()); |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
7 |
|
$continua = (int) $request->get('continua'); |
|
332
|
7 |
|
if ($continua === 0) { |
|
333
|
7 |
|
return new Response('OK'); |
|
334
|
|
|
} else { |
|
335
|
|
|
return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $id))); |
|
336
|
|
|
} |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
1 |
|
return $this->render( |
|
340
|
1 |
|
$crudtemplate, |
|
341
|
|
|
array( |
|
342
|
1 |
|
'entity' => $entity, |
|
343
|
1 |
|
'edit_form' => $editForm->createView(), |
|
344
|
1 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
|
345
|
|
|
) |
|
346
|
|
|
); |
|
347
|
|
|
} |
|
348
|
2 |
|
private function checkAggiornaRight($id) |
|
349
|
|
|
{ |
|
350
|
2 |
|
if ($id === 0) { |
|
351
|
|
|
if (!$this->getPermessi()->canCreate()) { |
|
352
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per creare questo contenuto"); |
|
|
|
|
|
|
353
|
|
|
} |
|
354
|
|
|
} else { |
|
355
|
2 |
|
if (!$this->getPermessi()->canUpdate()) { |
|
356
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per modificare questo contenuto"); |
|
|
|
|
|
|
357
|
|
|
} |
|
358
|
|
|
} |
|
359
|
1 |
|
} |
|
360
|
|
|
/** |
|
361
|
|
|
* Inline existing table entity. |
|
362
|
|
|
*/ |
|
363
|
2 |
|
public function aggiorna(Request $request, $id, $token) |
|
364
|
|
|
{ |
|
365
|
2 |
|
$this->checkAggiornaRight($id); |
|
366
|
|
|
|
|
367
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
|
368
|
1 |
|
$controller = $this->getController(); |
|
|
|
|
|
|
369
|
1 |
|
$entityclass = $this->getEntityClassName(); |
|
370
|
|
|
|
|
371
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
|
|
|
|
|
|
372
|
1 |
|
$queryBuilder = $em->createQueryBuilder(); |
|
373
|
1 |
|
$insert = ($id === 0); |
|
|
|
|
|
|
374
|
|
|
|
|
375
|
1 |
|
if ($insert) { |
|
376
|
|
|
//Insert |
|
377
|
|
|
$entity = new $entityclass(); |
|
378
|
|
|
$queryBuilder |
|
379
|
|
|
->insert($entityclass) |
|
380
|
|
|
; |
|
381
|
|
|
} else { |
|
382
|
|
|
//Update |
|
383
|
1 |
|
$entity = $em->getRepository($entityclass)->find($id); |
|
384
|
1 |
|
if (!$entity) { |
|
385
|
1 |
|
throw $this->createNotFoundException('Impossibile trovare l\'entità ' . $controller . ' per il record con id ' . $id); |
|
386
|
|
|
} |
|
387
|
|
|
$queryBuilder |
|
388
|
1 |
|
->update($entityclass, "u") |
|
|
|
|
|
|
389
|
1 |
|
->where("u.id = :id") |
|
|
|
|
|
|
390
|
1 |
|
->setParameter("id", $id); |
|
|
|
|
|
|
391
|
|
|
} |
|
392
|
1 |
|
$values = $request->get("values"); |
|
|
|
|
|
|
393
|
1 |
|
$isValidToken = $this->isCsrfTokenValid($id, $token); |
|
394
|
|
|
|
|
395
|
1 |
|
if (!$isValidToken) { |
|
396
|
1 |
|
throw $this->createNotFoundException('Token non valido'); |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
1 |
|
$querydaeseguire = false; |
|
400
|
|
|
|
|
401
|
1 |
|
foreach ($values as $value) { |
|
402
|
1 |
|
$fieldpieces = explode(".", $value["fieldname"]); |
|
|
|
|
|
|
403
|
1 |
|
$table = $fieldpieces[0]; |
|
|
|
|
|
|
404
|
|
|
//Si prende in considerazione solo i campi strettamente legati a questa entity |
|
405
|
1 |
|
if ($table == $controller && count($fieldpieces) == 2 && $value["fieldtype"] != 'join') { |
|
|
|
|
|
|
406
|
1 |
|
$field = $fieldpieces[1]; |
|
407
|
1 |
|
if ($insert) { |
|
408
|
|
|
$queryBuilder->setValue($field, ':' . $field); |
|
409
|
|
|
$queryBuilder->setParameter($field, $value["fieldvalue"]); |
|
|
|
|
|
|
410
|
|
|
$querydaeseguire = true; |
|
411
|
|
|
} else { |
|
412
|
1 |
|
$entityutils = new EntityUtils($em); |
|
|
|
|
|
|
413
|
1 |
|
$property = $entityutils->getEntityProperties($field, $entity); |
|
|
|
|
|
|
414
|
1 |
|
$nomefunzioneget = $property["get"]; |
|
|
|
|
|
|
415
|
1 |
|
if ($nomefunzioneget != $value["fieldvalue"]) { |
|
|
|
|
|
|
416
|
1 |
|
$querydaeseguire = true; |
|
417
|
1 |
|
$queryBuilder->set("u." . $field, ':' . $field); |
|
|
|
|
|
|
418
|
1 |
|
$queryBuilder->setParameter($field, $value["fieldvalue"]); |
|
|
|
|
|
|
419
|
|
|
} |
|
420
|
|
|
} |
|
421
|
|
|
} else { |
|
422
|
1 |
|
continue; |
|
423
|
|
|
} |
|
424
|
|
|
} |
|
425
|
1 |
|
if ($querydaeseguire) { |
|
426
|
1 |
|
$queryBuilder->getQuery()->execute(); |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
1 |
|
return new \Symfony\Component\HttpFoundation\JsonResponse(array("errcode" => 0, "message" => "Registrazione eseguita")); |
|
|
|
|
|
|
430
|
|
|
} |
|
431
|
|
|
/** |
|
432
|
|
|
* Deletes a table entity. |
|
433
|
|
|
*/ |
|
434
|
8 |
|
public function delete(Request $request, $token) |
|
435
|
|
|
{ |
|
436
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
|
437
|
8 |
|
if (!$this->getPermessi()->canDelete()) { |
|
438
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per eliminare questo contenuto"); |
|
|
|
|
|
|
439
|
|
|
} |
|
440
|
7 |
|
$entityclass = $this->getEntityClassName(); |
|
441
|
|
|
|
|
442
|
7 |
|
$isValidToken = $this->isCsrfTokenValid($this->getController(), $token); |
|
443
|
|
|
|
|
444
|
7 |
|
if (!$isValidToken) { |
|
445
|
|
|
throw $this->createNotFoundException('Token non valido'); |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
try { |
|
449
|
7 |
|
$em = $this->getDoctrine()->getManager(); |
|
|
|
|
|
|
450
|
7 |
|
$qb = $em->createQueryBuilder(); |
|
|
|
|
|
|
451
|
7 |
|
$ids = explode(',', $request->get('id')); |
|
452
|
7 |
|
$qb->delete($entityclass, 'u') |
|
453
|
7 |
|
->andWhere('u.id IN (:ids)') |
|
454
|
7 |
|
->setParameter('ids', $ids); |
|
455
|
|
|
|
|
456
|
7 |
|
$query = $qb->getQuery(); |
|
457
|
7 |
|
$query->execute(); |
|
458
|
2 |
|
} catch (\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException $e) { |
|
459
|
2 |
|
$response = new Response($e->getMessage()); |
|
460
|
2 |
|
$response->setStatusCode('501'); |
|
461
|
2 |
|
return $response; |
|
462
|
|
|
} catch (\Exception $e) { |
|
463
|
|
|
$response = new Response($e->getMessage()); |
|
464
|
|
|
$response->setStatusCode('200'); |
|
465
|
|
|
return $response; |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
5 |
|
return new Response('Operazione eseguita con successo'); |
|
469
|
|
|
} |
|
470
|
7 |
|
private function elencoModifiche($controller, $id) |
|
471
|
|
|
{ |
|
472
|
7 |
|
$em = $this->getDoctrine()->getManager(); |
|
|
|
|
|
|
473
|
7 |
|
$risultato = $em->getRepository('BiCoreBundle:Storicomodifiche')->findBy( |
|
474
|
|
|
array( |
|
475
|
7 |
|
'nometabella' => $controller, |
|
476
|
7 |
|
'idtabella' => $id, |
|
477
|
|
|
), |
|
478
|
7 |
|
array('giorno' => 'DESC') |
|
479
|
|
|
); |
|
480
|
|
|
|
|
481
|
7 |
|
return $risultato; |
|
482
|
|
|
} |
|
483
|
7 |
|
protected function getTabellaTemplate($controller) |
|
484
|
|
|
{ |
|
485
|
7 |
|
$tabellatemplate = $controller . '/Tabella/tabellaform.html.twig'; |
|
486
|
7 |
|
if (!$this->get('templating')->exists($tabellatemplate)) { |
|
487
|
6 |
|
$tabellatemplate = 'BiCoreBundle:' . $controller . ':Tabella/tabellaform.html.twig'; |
|
488
|
6 |
|
if (!$this->get('templating')->exists($tabellatemplate)) { |
|
489
|
5 |
|
$tabellatemplate = 'BiCoreBundle:Standard:Tabella/tabellaform.html.twig'; |
|
490
|
|
|
} |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
7 |
|
return $tabellatemplate; |
|
494
|
|
|
} |
|
495
|
10 |
|
protected function getCrudTemplate($bundle, $controller, $operation) |
|
496
|
|
|
{ |
|
497
|
10 |
|
$crudtemplate = $bundle . ':' . $controller . ':Crud/' . $operation . '.html.twig'; |
|
498
|
10 |
|
if (!$this->get('templating')->exists($crudtemplate)) { |
|
499
|
3 |
|
$crudtemplate = $controller . '/Crud/' . $operation . '.html.twig'; |
|
500
|
3 |
|
if (!$this->get('templating')->exists($crudtemplate)) { |
|
501
|
|
|
$crudtemplate = 'BiCoreBundle:Standard:Crud/' . $operation . '.html.twig'; |
|
502
|
|
|
} |
|
503
|
|
|
} |
|
504
|
10 |
|
return $crudtemplate; |
|
505
|
|
|
} |
|
506
|
|
|
/** |
|
507
|
|
|
* Returns the calling function through a backtrace |
|
508
|
|
|
*/ |
|
509
|
11 |
|
protected function getThisFunctionName() |
|
510
|
|
|
{ |
|
511
|
|
|
// a funciton x has called a function y which called this |
|
512
|
|
|
// see stackoverflow.com/questions/190421 |
|
513
|
11 |
|
$caller = debug_backtrace(); |
|
514
|
11 |
|
$caller = $caller[1]; |
|
515
|
11 |
|
return $caller['function']; |
|
516
|
|
|
} |
|
517
|
11 |
|
protected function getEntityClassNotation() |
|
518
|
|
|
{ |
|
519
|
11 |
|
$em = $this->get("doctrine")->getManager(); |
|
|
|
|
|
|
520
|
11 |
|
$entityutils = new EntityUtils($em); |
|
521
|
11 |
|
return $entityutils->getClassNameToShortcutNotations($this->getEntityClassName()); |
|
522
|
|
|
} |
|
523
|
14 |
|
protected function getEntityClassName() |
|
524
|
|
|
{ |
|
525
|
14 |
|
$em = $this->get("doctrine")->getManager(); |
|
|
|
|
|
|
526
|
14 |
|
$entityfinder = new Finder($em, $this->controller); |
|
527
|
14 |
|
return $entityfinder->getClassNameFromEntityName(); |
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
8 |
|
public function tabella(Request $request) |
|
531
|
|
|
{ |
|
532
|
8 |
|
if (!$this->permessi->canRead()) { |
|
533
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
|
|
|
|
|
|
534
|
|
|
} |
|
535
|
7 |
|
$doctrine = $this->get("doctrine"); |
|
|
|
|
|
|
536
|
|
|
//$em = $doctrine->getManager(); |
|
|
|
|
|
|
537
|
|
|
|
|
538
|
7 |
|
$parametripassati = array_merge($request->get("parametri"), array('user' => $this->getUser())); |
|
|
|
|
|
|
539
|
7 |
|
$parametriform = isset($parametripassati["parametriform"]) ? |
|
|
|
|
|
|
540
|
7 |
|
json_decode(ParametriTabella::getParameter($parametripassati["parametriform"]), true) : array(); |
|
|
|
|
|
|
541
|
7 |
|
$configurazionetabella = new Tabella($doctrine, $parametripassati); |
|
542
|
|
|
$parametritabella = array( |
|
|
|
|
|
|
543
|
7 |
|
'parametritabella' => $configurazionetabella->getConfigurazionecolonnetabella(), |
|
544
|
7 |
|
'recordstabella' => $configurazionetabella->getRecordstabella(), |
|
545
|
7 |
|
'paginacorrente' => $configurazionetabella->getPaginacorrente(), |
|
546
|
7 |
|
'paginetotali' => $configurazionetabella->getPaginetotali(), |
|
547
|
7 |
|
'righetotali' => $configurazionetabella->getRighetotali(), |
|
548
|
7 |
|
'traduzionefiltri' => $configurazionetabella->getTraduzionefiltri(), |
|
549
|
|
|
); |
|
550
|
7 |
|
$classbundle = ParametriTabella::getParameter($parametripassati["entityclass"]); |
|
|
|
|
|
|
551
|
|
|
//$formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller; |
|
552
|
7 |
|
$formbundle = ParametriTabella::getParameter($parametripassati["formclass"]); |
|
|
|
|
|
|
553
|
7 |
|
$formType = $formbundle . 'Type'; |
|
|
|
|
|
|
554
|
|
|
|
|
555
|
7 |
|
$entity = new $classbundle(); |
|
556
|
|
|
//$tablename = ParametriTabella::getParameter($parametripassati["tablename"]); |
|
|
|
|
|
|
557
|
7 |
|
$controller = ParametriTabella::getParameter($parametripassati["nomecontroller"]); |
|
|
|
|
|
|
558
|
7 |
|
$form = $this->createForm( |
|
|
|
|
|
|
559
|
7 |
|
$formType, |
|
560
|
7 |
|
$entity, |
|
561
|
|
|
array('attr' => array( |
|
562
|
7 |
|
'id' => 'formdati' . $controller, |
|
563
|
|
|
), |
|
564
|
7 |
|
'action' => $this->generateUrl($controller . '_new'), |
|
565
|
7 |
|
"parametriform" => $parametriform |
|
|
|
|
|
|
566
|
|
|
) |
|
567
|
|
|
); |
|
568
|
|
|
|
|
569
|
7 |
|
$parametri = array_merge($parametripassati, $parametritabella); |
|
|
|
|
|
|
570
|
7 |
|
$parametri["form"] = $form->createView(); |
|
|
|
|
|
|
571
|
|
|
|
|
572
|
7 |
|
$template = $controller . '/Tabella/tabellacontainer.html.twig'; |
|
|
|
|
|
|
573
|
7 |
|
$templatelocation = $controller . "/"; |
|
|
|
|
|
|
574
|
7 |
|
if (!$this->get('templating')->exists($template)) { |
|
575
|
6 |
|
$template = "BiCoreBundle:" . $controller . ':Tabella/tabellacontainer.html.twig'; |
|
|
|
|
|
|
576
|
6 |
|
$templatelocation = "BiCoreBundle:" . $controller . ":"; |
|
|
|
|
|
|
577
|
6 |
|
if (!$this->get('templating')->exists($template)) { |
|
578
|
5 |
|
$templatelocation = 'BiCoreBundle:Standard:'; |
|
579
|
5 |
|
$template = $templatelocation . 'Tabella/tabellacontainer.html.twig'; |
|
|
|
|
|
|
580
|
|
|
} |
|
581
|
|
|
} |
|
582
|
7 |
|
$parametri["templatelocation"] = $templatelocation; |
|
|
|
|
|
|
583
|
|
|
|
|
584
|
7 |
|
return $this->render( |
|
585
|
7 |
|
$template, |
|
586
|
|
|
array( |
|
587
|
7 |
|
'parametri' => $parametri |
|
588
|
|
|
) |
|
589
|
|
|
); |
|
590
|
|
|
} |
|
591
|
|
|
|
|
592
|
3 |
|
public function exportXls(Request $request) |
|
593
|
|
|
{ |
|
594
|
3 |
|
$doctrine = $this->get("doctrine"); |
|
|
|
|
|
|
595
|
|
|
|
|
596
|
|
|
try { |
|
597
|
3 |
|
$parametripassati = array_merge($request->get("parametri"), array('user' => $this->getUser())); |
|
|
|
|
|
|
598
|
3 |
|
$parametripassati["estraituttirecords"] = ParametriTabella::setParameter("1"); |
|
|
|
|
|
|
599
|
3 |
|
$configurazionetabella = new Tabella($doctrine, $parametripassati); |
|
|
|
|
|
|
600
|
|
|
$parametritabella = array( |
|
|
|
|
|
|
601
|
3 |
|
'parametritabella' => $configurazionetabella->getConfigurazionecolonnetabella(), |
|
602
|
3 |
|
'recordstabella' => $configurazionetabella->getRecordstabella(), |
|
603
|
3 |
|
'paginacorrente' => $configurazionetabella->getPaginacorrente(), |
|
604
|
3 |
|
'paginetotali' => $configurazionetabella->getPaginetotali(), |
|
605
|
3 |
|
'righetotali' => $configurazionetabella->getRighetotali(), |
|
606
|
3 |
|
'traduzionefiltri' => $configurazionetabella->getTraduzionefiltri(), |
|
607
|
3 |
|
'nomecontroller' => ParametriTabella::getParameter($parametripassati["nomecontroller"]), |
|
|
|
|
|
|
608
|
|
|
); |
|
609
|
3 |
|
$xls = new TabellaXls($this->container); |
|
|
|
|
|
|
610
|
3 |
|
$filexls = $xls->esportaexcel($parametritabella); |
|
|
|
|
|
|
611
|
3 |
|
if (file_exists($filexls)) { |
|
612
|
|
|
$response = array( |
|
613
|
3 |
|
'status' => '200', |
|
614
|
3 |
|
'file' => "data:application/vnd.ms-excel;base64," . base64_encode(file_get_contents($filexls)) |
|
|
|
|
|
|
615
|
|
|
); |
|
616
|
3 |
|
@unlink($filexls); |
|
617
|
|
|
} else { |
|
618
|
|
|
$response = array( |
|
619
|
3 |
|
'status' => '501', |
|
620
|
|
|
'file' => "Impossibile generare il file excel" |
|
|
|
|
|
|
621
|
|
|
); |
|
622
|
|
|
} |
|
623
|
|
|
} catch (\Exception $exc) { |
|
624
|
|
|
$response = array( |
|
625
|
|
|
'status' => '500', |
|
626
|
|
|
'file' => $exc->getFile() . " -> Riga: " . $exc->getLine() . " -> " . $exc->getMessage() |
|
|
|
|
|
|
627
|
|
|
); |
|
628
|
|
|
} |
|
629
|
|
|
|
|
630
|
3 |
|
return new JsonResponse($response); |
|
631
|
|
|
} |
|
632
|
|
|
} |
|
633
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.