1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
8
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
9
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\Finder; |
10
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\EntityUtils; |
11
|
|
|
use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella; |
12
|
|
|
use Symfony\Component\Asset\Packages; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @property \Symfony\Component\Security\Core\Security $user |
16
|
|
|
*/ |
17
|
|
|
class FiCrudController extends AbstractController |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
protected $bundle; |
21
|
|
|
protected $controller; |
22
|
|
|
protected $permessi; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Lists all tables entities. |
26
|
|
|
*/ |
27
|
6 |
|
public function index(Request $request, Packages $assetsmanager) |
28
|
|
|
{ |
29
|
6 |
|
$bundle = $this->getBundle(); |
|
|
|
|
30
|
6 |
|
$controller = $this->getController(); |
31
|
6 |
|
$idpassato = $request->get('id'); |
|
|
|
|
32
|
|
|
|
33
|
6 |
|
if (!$this->getPermessi()->canRead()) { |
34
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
|
|
|
|
35
|
|
|
} |
36
|
5 |
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName()); |
37
|
|
|
|
38
|
5 |
|
$entityclassnotation = $this->getEntityClassNotation(); |
39
|
5 |
|
$entityclass = $this->getEntityClassName(); |
|
|
|
|
40
|
|
|
|
41
|
5 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
42
|
|
|
|
43
|
|
|
$modellocolonne = array( |
44
|
|
|
/* |
|
|
|
|
45
|
|
|
$controller . ".nominativo" => array( |
46
|
|
|
"nometabella" => $controller, |
47
|
|
|
"nomecampo" => "nominativo", |
48
|
|
|
"etichetta" => "Nominativo", |
49
|
|
|
"ordine" => 10, |
50
|
|
|
"larghezza" => 200, |
51
|
|
|
"escluso" => false |
52
|
|
|
), |
53
|
|
|
$controller . ".datanascita" => array( |
54
|
|
|
"nometabella" => $controller, |
55
|
|
|
"nomecampo" => "datanascita", |
56
|
|
|
"etichetta" => "Data di nascita", |
57
|
|
|
"ordine" => 20, |
58
|
|
|
"larghezza" => 100, |
59
|
|
|
"escluso" => false |
60
|
|
|
), |
61
|
|
|
|
62
|
|
|
*/ |
63
|
5 |
|
); |
64
|
|
|
|
65
|
5 |
|
$colonneordinamento = array($controller . '.id' => "DESC"); |
|
|
|
|
66
|
5 |
|
$filtri = array(); |
|
|
|
|
67
|
5 |
|
$prefiltri = array(); |
|
|
|
|
68
|
5 |
|
$entityutils = new \Cdf\BiCoreBundle\Utils\Entity\EntityUtils($this->get("doctrine")->getManager()); |
|
|
|
|
69
|
5 |
|
$tablenamefromentity = $entityutils->getTableFromEntity($entityclass); |
70
|
5 |
|
$colonneordinamento = array($tablenamefromentity . '.id' => "DESC"); |
|
|
|
|
71
|
5 |
|
$parametritabella = array("em" => ParametriTabella::setParameter("default"), |
|
|
|
|
72
|
5 |
|
'tablename' => ParametriTabella::setParameter($tablenamefromentity), |
73
|
5 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
74
|
5 |
|
'bundle' => ParametriTabella::setParameter($bundle), |
75
|
5 |
|
'entityname' => ParametriTabella::setParameter($entityclassnotation), |
76
|
5 |
|
'entityclass' => ParametriTabella::setParameter($entityclass), |
77
|
5 |
|
'formclass' => ParametriTabella::setParameter($formclass), |
78
|
5 |
|
'modellocolonne' => ParametriTabella::setParameter(json_encode($modellocolonne)), |
79
|
5 |
|
'permessi' => ParametriTabella::setParameter(json_encode($this->getPermessi())), |
80
|
5 |
|
'urltabella' => ParametriTabella::setParameter($assetsmanager->getUrl('/') . $controller . '/' . 'tabella'), |
81
|
5 |
|
'baseurl' => ParametriTabella::setParameter($assetsmanager->getUrl('/')), |
82
|
5 |
|
'idpassato' => ParametriTabella::setParameter($idpassato), |
83
|
5 |
|
'titolotabella' => ParametriTabella::setParameter("Elenco " . $controller), |
|
|
|
|
84
|
5 |
|
'multiselezione' => ParametriTabella::setParameter("0"), |
|
|
|
|
85
|
5 |
|
'paginacorrente' => ParametriTabella::setParameter("1"), |
|
|
|
|
86
|
5 |
|
'paginetotali' => ParametriTabella::setParameter(""), |
|
|
|
|
87
|
5 |
|
'righetotali' => ParametriTabella::setParameter("0"), |
|
|
|
|
88
|
5 |
|
'righeperpagina' => ParametriTabella::setParameter("15"), |
|
|
|
|
89
|
5 |
|
'estraituttirecords' => ParametriTabella::setParameter("0"), |
|
|
|
|
90
|
5 |
|
'colonneordinamento' => ParametriTabella::setParameter(json_encode($colonneordinamento)), |
91
|
5 |
|
'filtri' => ParametriTabella::setParameter(json_encode($filtri)), |
92
|
5 |
|
'prefiltri' => ParametriTabella::setParameter(json_encode($prefiltri)), |
93
|
5 |
|
'traduzionefiltri' => ParametriTabella::setParameter(""), |
|
|
|
|
94
|
|
|
); |
95
|
|
|
|
96
|
5 |
|
return $this->render($crudtemplate, array('parametritabella' => $parametritabella,)); |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
private function getParametroIndexDettaglio($parametripassati, $keyparametro, $defaultvalue) |
100
|
|
|
{ |
101
|
1 |
|
if (isset($parametripassati[$keyparametro])) { |
102
|
|
|
$parametro = $parametripassati[$keyparametro]; |
103
|
|
|
} else { |
104
|
1 |
|
$parametro = $defaultvalue; |
105
|
|
|
} |
106
|
1 |
|
return $parametro; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Lists all tables entities. |
111
|
|
|
*/ |
112
|
1 |
|
public function indexDettaglio(Request $request, Packages $assetsmanager) |
113
|
|
|
{ |
114
|
1 |
|
if (!$this->getPermessi()->canRead()) { |
115
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
119
|
1 |
|
$controller = $this->getController(); |
|
|
|
|
120
|
1 |
|
$parametripassati = json_decode($request->get('parametripassati'), true); |
121
|
|
|
|
122
|
1 |
|
$filtri = $this->getParametroIndexDettaglio($parametripassati, "filtri", array()); |
|
|
|
|
123
|
1 |
|
$prefiltri = $this->getParametroIndexDettaglio($parametripassati, "prefiltri", array()); |
|
|
|
|
124
|
1 |
|
$titolotabella = $this->getParametroIndexDettaglio($parametripassati, "titolotabella", "Elenco " . $controller); |
|
|
|
|
125
|
1 |
|
$modellocolonne = $this->getParametroIndexDettaglio($parametripassati, "modellocolonne", array()); |
|
|
|
|
126
|
1 |
|
$colonneordinamento = $this->getParametroIndexDettaglio($parametripassati, "colonneordinamento", array()); |
|
|
|
|
127
|
1 |
|
$multiselezione = $this->getParametroIndexDettaglio($parametripassati, "multiselezione", 0); |
|
|
|
|
128
|
1 |
|
$parametriform = $this->getParametroIndexDettaglio($parametripassati, "parametriform", array()); |
|
|
|
|
129
|
|
|
|
130
|
1 |
|
$template = $bundle . ':' . $controller . ':' . $this->getThisFunctionName() . '.html.twig'; |
131
|
1 |
|
if (!$this->get('templating')->exists($template)) { |
132
|
1 |
|
$template = $controller . '/Crud/' . $this->getThisFunctionName() . '.html.twig'; |
133
|
|
|
} |
134
|
|
|
|
135
|
1 |
|
$entityclassnotation = $this->getEntityClassNotation(); |
136
|
1 |
|
$entityclass = $this->getEntityClassName(); |
|
|
|
|
137
|
|
|
|
138
|
1 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
139
|
|
|
|
140
|
1 |
|
$entityutils = new \Cdf\BiCoreBundle\Utils\Entity\EntityUtils($this->get("doctrine")->getManager()); |
|
|
|
|
141
|
|
|
|
142
|
1 |
|
$tablenamefromentity = $entityutils->getTableFromEntity($entityclass); |
143
|
1 |
|
$parametritabella = array("em" => ParametriTabella::setParameter("default"), |
|
|
|
|
144
|
1 |
|
'tablename' => ParametriTabella::setParameter($tablenamefromentity), |
145
|
1 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
146
|
1 |
|
'bundle' => ParametriTabella::setParameter($bundle), |
147
|
1 |
|
'entityname' => ParametriTabella::setParameter($entityclassnotation), |
148
|
1 |
|
'entityclass' => ParametriTabella::setParameter($entityclass), |
149
|
1 |
|
'formclass' => ParametriTabella::setParameter($formclass), |
150
|
1 |
|
'parametriform' => ParametriTabella::setParameter(json_encode($parametriform)), |
151
|
1 |
|
'modellocolonne' => ParametriTabella::setParameter(json_encode($modellocolonne)), |
152
|
1 |
|
'permessi' => ParametriTabella::setParameter(json_encode($this->getPermessi())), |
153
|
1 |
|
'urltabella' => ParametriTabella::setParameter($assetsmanager->getUrl('/') . $controller . '/' . 'tabella'), |
154
|
1 |
|
'baseurl' => ParametriTabella::setParameter($assetsmanager->getUrl('/')), |
155
|
1 |
|
'idpassato' => ParametriTabella::setParameter(0), |
156
|
1 |
|
'titolotabella' => ParametriTabella::setParameter($titolotabella), |
157
|
1 |
|
'multiselezione' => ParametriTabella::setParameter($multiselezione), |
158
|
1 |
|
'paginacorrente' => ParametriTabella::setParameter("1"), |
|
|
|
|
159
|
1 |
|
'paginetotali' => ParametriTabella::setParameter(""), |
|
|
|
|
160
|
1 |
|
'righeperpagina' => ParametriTabella::setParameter("15"), |
|
|
|
|
161
|
1 |
|
'colonneordinamento' => ParametriTabella::setParameter(json_encode($colonneordinamento)), |
162
|
1 |
|
'filtri' => ParametriTabella::setParameter(json_encode($filtri)), |
163
|
1 |
|
'prefiltri' => ParametriTabella::setParameter(json_encode($prefiltri)), |
164
|
1 |
|
'traduzionefiltri' => ParametriTabella::setParameter(""), |
|
|
|
|
165
|
|
|
); |
166
|
|
|
|
167
|
1 |
|
return $this->render( |
168
|
1 |
|
$template, |
169
|
|
|
array( |
170
|
1 |
|
'parametritabella' => $parametritabella, |
171
|
|
|
) |
172
|
|
|
); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Displays a form to create a new table entity. |
177
|
|
|
*/ |
178
|
7 |
|
public function new(Request $request) |
179
|
|
|
{ |
180
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
181
|
7 |
|
$bundle = $this->getBundle(); |
|
|
|
|
182
|
7 |
|
$controller = $this->getController(); |
183
|
7 |
|
if (!$this->getPermessi()->canCreate()) { |
184
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per creare questo contenuto"); |
|
|
|
|
185
|
|
|
} |
186
|
|
|
|
187
|
6 |
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName()); |
|
|
|
|
188
|
6 |
|
$tabellatemplate = $this->getTabellaTemplate($controller); |
189
|
|
|
|
190
|
6 |
|
$parametriform = $request->get("parametriform") ? json_decode($request->get("parametriform"), true) : array(); |
|
|
|
|
191
|
|
|
|
192
|
6 |
|
$entityclass = $this->getEntityClassName(); |
193
|
6 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
194
|
|
|
|
195
|
6 |
|
$entity = new $entityclass(); |
|
|
|
|
196
|
6 |
|
$formType = $formclass . 'Type'; |
197
|
6 |
|
$form = $this->createForm($formType, $entity, array('attr' => array( |
|
|
|
|
198
|
6 |
|
'id' => 'formdati' . $controller, |
199
|
|
|
), |
200
|
6 |
|
'action' => $this->generateUrl($controller . '_new'), "parametriform" => $parametriform |
|
|
|
|
201
|
|
|
)); |
202
|
|
|
|
203
|
6 |
|
$form->handleRequest($request); |
204
|
|
|
|
205
|
|
|
$twigparms = array( |
206
|
6 |
|
'form' => $form->createView(), |
207
|
6 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
208
|
6 |
|
'tabellatemplate' => $tabellatemplate |
209
|
|
|
); |
210
|
|
|
|
211
|
6 |
|
if ($form->isSubmitted()) { |
212
|
6 |
|
if ($form->isValid()) { |
213
|
5 |
|
$entity = $form->getData(); |
214
|
|
|
|
215
|
5 |
|
$entityManager = $this->getDoctrine()->getManager(); |
216
|
5 |
|
$entityManager->persist($entity); |
217
|
5 |
|
$entityManager->flush(); |
218
|
5 |
|
return new Response( |
219
|
5 |
|
$this->renderView($crudtemplate, $twigparms), |
220
|
5 |
|
200 |
221
|
|
|
); |
222
|
|
|
} else { |
223
|
|
|
//Quando non passa la validazione |
224
|
1 |
|
return new Response( |
225
|
1 |
|
$this->renderView($crudtemplate, $twigparms), |
226
|
1 |
|
400 |
227
|
|
|
); |
228
|
|
|
} |
229
|
|
|
} else { |
230
|
|
|
//Quando viene richiesta una "nuova" new |
231
|
6 |
|
return new Response( |
232
|
6 |
|
$this->renderView($crudtemplate, $twigparms), |
233
|
6 |
|
200 |
234
|
|
|
); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Displays a form to edit an existing table entity. |
240
|
|
|
*/ |
241
|
8 |
|
public function edit(Request $request, $id) |
|
|
|
|
242
|
|
|
{ |
243
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
244
|
8 |
|
$bundle = $this->getBundle(); |
|
|
|
|
245
|
8 |
|
$controller = $this->getController(); |
246
|
|
|
|
247
|
8 |
|
if (!$this->getPermessi()->canUpdate()) { |
248
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per modificare questo contenuto"); |
|
|
|
|
249
|
|
|
} |
250
|
7 |
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName()); |
|
|
|
|
251
|
7 |
|
$tabellatemplate = $this->getTabellaTemplate($controller); |
252
|
|
|
|
253
|
7 |
|
$entityclass = $this->getEntityClassName(); |
254
|
7 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
255
|
|
|
|
256
|
7 |
|
$formType = $formclass . 'Type'; |
257
|
|
|
|
258
|
7 |
|
$elencomodifiche = $this->elencoModifiche($controller, $id); |
259
|
|
|
|
260
|
7 |
|
$em = $this->getDoctrine()->getManager(); |
261
|
|
|
|
262
|
7 |
|
$entity = $em->getRepository($entityclass)->find($id); |
263
|
|
|
|
264
|
7 |
|
if (!$entity) { |
265
|
1 |
|
throw $this->createNotFoundException('Impossibile trovare l\'entità ' . $controller . ' del record con id ' . $id . '.'); |
266
|
|
|
} |
267
|
|
|
|
268
|
7 |
|
$editForm = $this->createForm( |
269
|
7 |
|
$formType, |
270
|
7 |
|
$entity, |
271
|
|
|
array('attr' => array( |
272
|
7 |
|
'id' => 'formdati' . $controller, |
273
|
|
|
), |
274
|
7 |
|
'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())), |
275
|
|
|
) |
276
|
|
|
); |
277
|
|
|
|
278
|
7 |
|
return $this->render( |
279
|
7 |
|
$crudtemplate, |
280
|
|
|
array( |
281
|
7 |
|
'entity' => $entity, |
282
|
7 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
283
|
7 |
|
'tabellatemplate' => $tabellatemplate, |
284
|
7 |
|
'edit_form' => $editForm->createView(), |
285
|
7 |
|
'elencomodifiche' => $elencomodifiche, |
286
|
|
|
) |
287
|
|
|
); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Edits an existing table entity. |
292
|
|
|
*/ |
293
|
9 |
|
public function update(Request $request, $id) |
294
|
|
|
{ |
295
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
296
|
9 |
|
$bundle = $this->getBundle(); |
|
|
|
|
297
|
9 |
|
$controller = $this->getController(); |
298
|
9 |
|
if (!$this->getPermessi()->canUpdate()) { |
299
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per modificare questo contenuto"); |
|
|
|
|
300
|
|
|
} |
301
|
8 |
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, "edit"); |
|
|
|
|
302
|
|
|
|
303
|
8 |
|
$entityclass = $this->getEntityClassName(); |
304
|
8 |
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
305
|
8 |
|
$formType = $formclass . 'Type'; |
|
|
|
|
306
|
|
|
|
307
|
8 |
|
$em = $this->getDoctrine()->getManager(); |
308
|
|
|
|
309
|
8 |
|
$entity = $em->getRepository($entityclass)->find($id); |
310
|
|
|
|
311
|
8 |
|
if (!$entity) { |
312
|
1 |
|
throw $this->createNotFoundException('Impossibile trovare l\'entità ' . $controller . ' per il record con id ' . $id); |
313
|
|
|
} |
314
|
|
|
|
315
|
7 |
|
$editForm = $this->createForm( |
316
|
7 |
|
$formType, |
317
|
7 |
|
$entity, |
318
|
|
|
array('attr' => array( |
319
|
7 |
|
'id' => 'formdati' . $controller, |
320
|
|
|
), |
321
|
7 |
|
'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())), |
322
|
|
|
) |
323
|
|
|
); |
324
|
|
|
|
325
|
7 |
|
$editForm->submit($request->request->get($editForm->getName())); |
326
|
|
|
|
327
|
7 |
|
if ($editForm->isValid()) { |
328
|
7 |
|
$originalData = $em->getUnitOfWork()->getOriginalEntityData($entity); |
329
|
|
|
|
330
|
7 |
|
$em->persist($entity); |
331
|
7 |
|
$em->flush(); |
332
|
|
|
|
333
|
7 |
|
$newData = $em->getUnitOfWork()->getOriginalEntityData($entity); |
|
|
|
|
334
|
7 |
|
$repoStorico = $em->getRepository("BiCoreBundle:Storicomodifiche"); |
|
|
|
|
335
|
7 |
|
$changes = $repoStorico->isRecordChanged($controller, $originalData, $newData); |
|
|
|
|
336
|
|
|
|
337
|
7 |
|
if ($changes) { |
338
|
2 |
|
$repoStorico->saveHistory($controller, $changes, $id, $this->getUser()); |
339
|
|
|
} |
340
|
|
|
|
341
|
7 |
|
$continua = (int) $request->get('continua'); |
342
|
7 |
|
if ($continua === 0) { |
343
|
7 |
|
return new Response('OK'); |
344
|
|
|
} else { |
345
|
|
|
return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $id))); |
346
|
|
|
} |
347
|
|
|
} |
348
|
|
|
|
349
|
1 |
|
return $this->render( |
350
|
1 |
|
$crudtemplate, |
351
|
|
|
array( |
352
|
1 |
|
'entity' => $entity, |
353
|
1 |
|
'edit_form' => $editForm->createView(), |
354
|
1 |
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
355
|
|
|
) |
356
|
|
|
); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* Deletes a table entity. |
361
|
|
|
*/ |
362
|
8 |
|
public function delete(Request $request) |
363
|
|
|
{ |
364
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
365
|
8 |
|
if (!$this->getPermessi()->canDelete()) { |
366
|
1 |
|
throw new AccessDeniedException("Non si hanno i permessi per eliminare questo contenuto"); |
|
|
|
|
367
|
|
|
} |
368
|
7 |
|
$entityclass = $this->getEntityClassName(); |
369
|
|
|
|
370
|
|
|
|
371
|
|
|
try { |
372
|
7 |
|
$em = $this->getDoctrine()->getManager(); |
|
|
|
|
373
|
7 |
|
$qb = $em->createQueryBuilder(); |
|
|
|
|
374
|
7 |
|
$ids = explode(',', $request->get('id')); |
375
|
7 |
|
$qb->delete($entityclass, 'u') |
376
|
7 |
|
->andWhere('u.id IN (:ids)') |
377
|
7 |
|
->setParameter('ids', $ids); |
378
|
|
|
|
379
|
7 |
|
$query = $qb->getQuery(); |
380
|
7 |
|
$query->execute(); |
381
|
2 |
|
} catch (\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException $e) { |
382
|
2 |
|
$response = new Response($e->getMessage()); |
383
|
2 |
|
$response->setStatusCode('501'); |
384
|
2 |
|
return $response; |
385
|
|
|
} catch (\Exception $e) { |
386
|
|
|
$response = new Response($e->getMessage()); |
387
|
|
|
$response->setStatusCode('200'); |
388
|
|
|
return $response; |
389
|
|
|
} |
390
|
|
|
|
391
|
5 |
|
return new Response('Operazione eseguita con successo'); |
392
|
|
|
} |
393
|
|
|
|
394
|
7 |
|
private function elencoModifiche($controller, $id) |
395
|
|
|
{ |
396
|
7 |
|
$em = $this->getDoctrine()->getManager(); |
|
|
|
|
397
|
7 |
|
$risultato = $em->getRepository('BiCoreBundle:Storicomodifiche')->findBy( |
398
|
|
|
array( |
399
|
7 |
|
'nometabella' => $controller, |
400
|
7 |
|
'idtabella' => $id, |
401
|
|
|
), |
402
|
7 |
|
array('giorno' => 'DESC') |
403
|
|
|
); |
404
|
|
|
|
405
|
7 |
|
return $risultato; |
406
|
|
|
} |
407
|
|
|
|
408
|
7 |
|
protected function getTabellaTemplate($controller) |
409
|
|
|
{ |
410
|
7 |
|
$tabellatemplate = $controller . '/Tabella/tabellaform.html.twig'; |
411
|
7 |
|
if (!$this->get('templating')->exists($tabellatemplate)) { |
412
|
6 |
|
$tabellatemplate = 'BiCoreBundle:' . $controller . ':Tabella/tabellaform.html.twig'; |
413
|
6 |
|
if (!$this->get('templating')->exists($tabellatemplate)) { |
414
|
5 |
|
$tabellatemplate = 'BiCoreBundle:Standard:Tabella/tabellaform.html.twig'; |
415
|
|
|
} |
416
|
|
|
} |
417
|
|
|
|
418
|
7 |
|
return $tabellatemplate; |
419
|
|
|
} |
420
|
|
|
|
421
|
9 |
|
protected function getCrudTemplate($bundle, $controller, $operation) |
422
|
|
|
{ |
423
|
9 |
|
$crudtemplate = $bundle . ':' . $controller . ':Crud/' . $operation . '.html.twig'; |
424
|
9 |
|
if (!$this->get('templating')->exists($crudtemplate)) { |
425
|
3 |
|
$crudtemplate = $controller . '/Crud/' . $operation . '.html.twig'; |
426
|
3 |
|
if (!$this->get('templating')->exists($crudtemplate)) { |
427
|
|
|
$crudtemplate = 'BiCoreBundle:Standard:Crud/' . $operation . '.html.twig'; |
428
|
|
|
} |
429
|
|
|
} |
430
|
9 |
|
return $crudtemplate; |
431
|
|
|
} |
432
|
|
|
|
433
|
11 |
|
protected function getBundle() |
434
|
|
|
{ |
435
|
11 |
|
return $this->bundle; |
436
|
|
|
} |
437
|
|
|
|
438
|
11 |
|
protected function getController() |
439
|
|
|
{ |
440
|
11 |
|
return $this->controller; |
441
|
|
|
} |
442
|
|
|
|
443
|
11 |
|
protected function getPermessi() |
444
|
|
|
{ |
445
|
11 |
|
return $this->permessi; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* Returns the calling function through a backtrace |
450
|
|
|
*/ |
451
|
10 |
|
protected function getThisFunctionName() |
452
|
|
|
{ |
453
|
|
|
// a funciton x has called a function y which called this |
454
|
|
|
// see stackoverflow.com/questions/190421 |
455
|
10 |
|
$caller = debug_backtrace(); |
456
|
10 |
|
$caller = $caller[1]; |
457
|
10 |
|
return $caller['function']; |
458
|
|
|
} |
459
|
|
|
|
460
|
10 |
|
protected function getEntityClassNotation() |
461
|
|
|
{ |
462
|
10 |
|
$em = $this->get("doctrine")->getManager(); |
|
|
|
|
463
|
10 |
|
$entityfinder = new Finder($em, $this->controller); |
464
|
10 |
|
$entityutils = new EntityUtils($em); |
|
|
|
|
465
|
10 |
|
return $entityutils->getClassNameToShortcutNotations($entityfinder->getClassNameFromEntityName()); |
466
|
|
|
} |
467
|
|
|
|
468
|
10 |
|
protected function getEntityClassName() |
469
|
|
|
{ |
470
|
10 |
|
$em = $this->get("doctrine")->getManager(); |
|
|
|
|
471
|
10 |
|
$entityfinder = new Finder($em, $this->controller); |
472
|
10 |
|
return $entityfinder->getClassNameFromEntityName(); |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
|
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.