1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Qui Bundle */ |
4
|
|
|
//namespace Fi\DemoBundle\Controller; |
5
|
|
|
|
6
|
|
|
namespace Fi\CoreBundle\Controller; |
7
|
|
|
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* OpzioniTabella controller. |
14
|
|
|
*/ |
15
|
|
|
class OpzioniTabellaController extends FiCoreController |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Lists all opzioniTabella entities. |
20
|
|
|
*/ |
21
|
1 |
|
public function indexAction(Request $request) |
22
|
|
|
{ |
23
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
24
|
1 |
|
$this->setup($request); |
25
|
1 |
|
$namespace = $this->getNamespace(); |
|
|
|
|
26
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
27
|
1 |
|
$controller = $this->getController(); |
28
|
1 |
|
$container = $this->container; |
|
|
|
|
29
|
|
|
|
30
|
1 |
|
$nomebundle = $namespace . $bundle . 'Bundle'; |
31
|
|
|
|
32
|
|
|
$dettaglij = array( |
33
|
|
|
'descrizione' => array( |
34
|
|
|
array( |
35
|
1 |
|
'nomecampo' => 'descrizione', |
36
|
1 |
|
'lunghezza' => '400', |
37
|
1 |
|
'descrizione' => 'Descrizione', |
38
|
1 |
|
'tipo' => 'text',),), |
39
|
|
|
'parametro' => array( |
40
|
|
|
array( |
41
|
1 |
|
'nomecampo' => 'parametro', |
42
|
1 |
|
'lunghezza' => '300', |
43
|
1 |
|
'descrizione' => 'Parametro', |
44
|
1 |
|
'tipo' => 'text',),), |
45
|
|
|
'valore' => array( |
46
|
|
|
array( |
47
|
1 |
|
'nomecampo' => 'valore', |
48
|
1 |
|
'lunghezza' => '300', |
49
|
1 |
|
'descrizione' => 'Valore', |
50
|
1 |
|
'tipo' => 'text',),), |
51
|
|
|
'tabelle_id' => array( |
52
|
|
|
array( |
53
|
1 |
|
'nomecampo' => 'tabelle.nometabella', |
54
|
1 |
|
'lunghezza' => '400', |
55
|
1 |
|
'descrizione' => 'Tabella', |
56
|
1 |
|
'tipo' => 'text',), |
57
|
1 |
|
), |
58
|
1 |
|
); |
59
|
|
|
|
60
|
1 |
|
$escludi = array(); |
|
|
|
|
61
|
|
|
$paricevuti = array( |
62
|
1 |
|
'nomebundle' => $nomebundle, |
63
|
1 |
|
'nometabella' => $controller, |
64
|
1 |
|
'dettaglij' => $dettaglij, |
65
|
1 |
|
'escludere' => $escludi, |
66
|
1 |
|
'container' => $container, |
67
|
1 |
|
); |
68
|
|
|
|
69
|
1 |
|
$griglia = $this->get("ficorebundle.griglia"); |
|
|
|
|
70
|
1 |
|
$testatagriglia = $griglia->testataPerGriglia($paricevuti); |
71
|
|
|
|
72
|
1 |
|
$testatagriglia['multisearch'] = 1; |
73
|
1 |
|
$testatagriglia['showconfig'] = 1; |
|
|
|
|
74
|
1 |
|
$testatagriglia['showadd'] = 1; |
|
|
|
|
75
|
1 |
|
$testatagriglia['showedit'] = 1; |
|
|
|
|
76
|
1 |
|
$testatagriglia['showdel'] = 1; |
|
|
|
|
77
|
1 |
|
$testatagriglia['editinline'] = 0; |
|
|
|
|
78
|
|
|
|
79
|
1 |
|
$testatagriglia['parametritesta'] = json_encode($paricevuti); |
80
|
1 |
|
$this->setParametriGriglia(array('request' => $request)); |
81
|
1 |
|
$testatagriglia['parametrigriglia'] = json_encode(self::$parametrigriglia); |
82
|
|
|
|
83
|
1 |
|
$testata = json_encode($testatagriglia); |
|
|
|
|
84
|
|
|
$twigparms = array( |
85
|
1 |
|
'nomecontroller' => $controller, |
86
|
1 |
|
'testata' => $testata, |
87
|
1 |
|
); |
88
|
|
|
|
89
|
1 |
|
return $this->render($nomebundle . ':' . $controller . ':index.html.twig', $twigparms); |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
public function setParametriGriglia($prepar = array()) |
93
|
|
|
{ |
94
|
1 |
|
$this->setup($prepar['request']); |
95
|
1 |
|
$namespace = $this->getNamespace(); |
|
|
|
|
96
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
97
|
1 |
|
$controller = $this->getController(); |
98
|
|
|
|
99
|
1 |
|
$nomebundle = $namespace . $bundle . 'Bundle'; |
|
|
|
|
100
|
1 |
|
$escludi = array(); |
|
|
|
|
101
|
1 |
|
$tabellej = array(); |
|
|
|
|
102
|
1 |
|
$tabellej['tabelle_id'] = array('tabella' => 'tabelle', 'campi' => array('nometabella')); |
103
|
|
|
|
104
|
|
|
$paricevuti = array( |
105
|
1 |
|
'container' => $this->container, |
106
|
1 |
|
'nomebundle' => $nomebundle, |
107
|
1 |
|
'tabellej' => $tabellej, |
108
|
1 |
|
'nometabella' => $controller, |
109
|
1 |
|
'escludere' => $escludi,); |
110
|
|
|
|
111
|
1 |
|
if (!empty($prepar)) { |
112
|
1 |
|
$paricevuti = array_merge($paricevuti, $prepar); |
113
|
1 |
|
} |
114
|
|
|
|
115
|
1 |
|
self::$parametrigriglia = $paricevuti; |
116
|
1 |
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Creates a new table entity. |
120
|
|
|
*/ |
121
|
1 |
|
public function createAction(Request $request) |
122
|
|
|
{ |
123
|
1 |
|
$this->setup($request); |
124
|
1 |
|
$namespace = $this->getNamespace(); |
|
|
|
|
125
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
126
|
1 |
|
$controller = $this->getController(); |
127
|
|
|
|
128
|
1 |
|
if (!self::$canCreate) { |
129
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per creare questo contenuto"); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
1 |
|
$nomebundle = $namespace . $bundle . 'Bundle'; |
|
|
|
|
133
|
1 |
|
$classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller; |
134
|
1 |
|
$formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller; |
|
|
|
|
135
|
|
|
|
136
|
1 |
|
$entity = new $classbundle(); |
|
|
|
|
137
|
1 |
|
$formType = $formbundle . 'Type'; |
138
|
|
|
|
139
|
1 |
|
$form = $this->createForm( |
140
|
1 |
|
$formType, |
141
|
1 |
|
$entity, |
142
|
|
|
array('attr' => array( |
143
|
1 |
|
'id' => 'formdati' . $controller, |
144
|
1 |
|
), |
145
|
1 |
|
'action' => $this->generateUrl($controller . '_create'), |
146
|
|
|
) |
147
|
1 |
|
); |
148
|
|
|
|
149
|
1 |
|
$form->submit($request->request->get($form->getName())); |
150
|
|
|
|
151
|
1 |
|
if ($form->isValid()) { |
152
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
153
|
1 |
|
$em->persist($entity); |
154
|
1 |
|
$em->flush(); |
155
|
1 |
|
$em->getConfiguration()->getResultCacheImpl()->delete($controller); |
156
|
|
|
|
157
|
1 |
|
$continua = (int) $request->get('continua'); |
158
|
1 |
|
if ($continua === 0) { |
159
|
1 |
|
return new Response('OK'); |
160
|
|
|
} else { |
161
|
|
|
return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $entity->getId()))); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $this->render( |
166
|
|
|
$nomebundle . ':' . $controller . ':new.html.twig', |
167
|
|
|
array( |
168
|
|
|
'nomecontroller' => $controller, |
169
|
|
|
'entity' => $entity, |
170
|
|
|
'form' => $form->createView(), |
171
|
|
|
) |
172
|
|
|
); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Edits an existing table entity. |
177
|
|
|
*/ |
178
|
1 |
|
public function updateAction(Request $request, $id) |
179
|
|
|
{ |
180
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
181
|
1 |
|
$this->setup($request); |
182
|
1 |
|
$namespace = $this->getNamespace(); |
|
|
|
|
183
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
184
|
1 |
|
$controller = $this->getController(); |
185
|
|
|
|
186
|
1 |
|
if (!self::$canUpdate) { |
187
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per aggiornare questo contenuto"); |
|
|
|
|
188
|
|
|
} |
189
|
|
|
|
190
|
1 |
|
$nomebundle = $namespace . $bundle . 'Bundle'; |
191
|
1 |
|
$formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller; |
192
|
1 |
|
$formType = $formbundle . 'Type'; |
|
|
|
|
193
|
|
|
|
194
|
1 |
|
$repoStorico = $this->container->get('Storicomodifiche_repository'); |
195
|
|
|
|
196
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
197
|
|
|
|
198
|
1 |
|
$entity = $em->getRepository($nomebundle . ':' . $controller)->find($id); |
199
|
|
|
|
200
|
1 |
|
if (!$entity) { |
201
|
|
|
throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.'); |
202
|
|
|
} |
203
|
|
|
|
204
|
1 |
|
$deleteForm = $this->createDeleteForm($id); |
205
|
|
|
|
206
|
1 |
|
$editForm = $this->createForm( |
207
|
1 |
|
$formType, |
208
|
1 |
|
$entity, |
209
|
|
|
array('attr' => array( |
210
|
1 |
|
'id' => 'formdati' . $controller, |
211
|
1 |
|
), |
212
|
1 |
|
'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())), |
213
|
|
|
) |
214
|
1 |
|
); |
215
|
|
|
|
216
|
1 |
|
$editForm->submit($request->request->get($editForm->getName())); |
217
|
|
|
|
218
|
1 |
|
if ($editForm->isValid()) { |
219
|
1 |
|
$originalData = $em->getUnitOfWork()->getOriginalEntityData($entity); |
220
|
|
|
|
221
|
1 |
|
$em->persist($entity); |
222
|
1 |
|
$em->flush(); |
223
|
1 |
|
$em->getConfiguration()->getResultCacheImpl()->delete($controller); |
224
|
|
|
|
225
|
1 |
|
$newData = $em->getUnitOfWork()->getOriginalEntityData($entity); |
226
|
1 |
|
$changes = $repoStorico->isRecordChanged($nomebundle, $controller, $originalData, $newData); |
227
|
|
|
|
228
|
1 |
|
if ($changes) { |
229
|
|
|
$repoStorico->saveHistory($controller, $changes, $id, $this->getUser()); |
230
|
|
|
} |
231
|
|
|
|
232
|
1 |
|
$continua = (int) $request->get('continua'); |
233
|
1 |
|
if ($continua === 0) { |
234
|
1 |
|
return new Response('OK'); |
235
|
|
|
} else { |
236
|
|
|
return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $id))); |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
return $this->render( |
241
|
|
|
$nomebundle . ':' . $controller . ':edit.html.twig', |
242
|
|
|
array( |
243
|
|
|
'entity' => $entity, |
244
|
|
|
'edit_form' => $editForm->createView(), |
245
|
|
|
'delete_form' => $deleteForm->createView(), |
246
|
|
|
'nomecontroller' => $controller, |
247
|
|
|
) |
248
|
|
|
); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Deletes a table entity. |
253
|
|
|
*/ |
254
|
1 |
|
public function deleteAction(Request $request) |
255
|
|
|
{ |
256
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
257
|
1 |
|
$this->setup($request); |
258
|
1 |
|
if (!self::$canDelete) { |
259
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per aggiornare questo contenuto"); |
|
|
|
|
260
|
|
|
} |
261
|
1 |
|
$namespace = $this->getNamespace(); |
|
|
|
|
262
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
263
|
1 |
|
$controller = $this->getController(); |
264
|
|
|
|
265
|
1 |
|
$nomebundle = $namespace . $bundle . 'Bundle'; |
266
|
|
|
|
267
|
|
|
try { |
268
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
|
|
|
|
269
|
1 |
|
$qb = $em->createQueryBuilder(); |
|
|
|
|
270
|
1 |
|
$ids = explode(',', $request->get('id')); |
271
|
1 |
|
$qb->delete($nomebundle . ':' . $controller, 'u') |
272
|
1 |
|
->andWhere('u.id IN (:ids)') |
273
|
1 |
|
->setParameter('ids', $ids); |
274
|
|
|
|
275
|
1 |
|
$query = $qb->getQuery(); |
276
|
1 |
|
$query->execute(); |
277
|
1 |
|
$em->getConfiguration()->getResultCacheImpl()->delete($controller); |
278
|
1 |
|
} catch (\Exception $e) { |
279
|
|
|
$response = new Response(); |
280
|
|
|
$response->setStatusCode('200'); |
281
|
|
|
|
282
|
|
|
return new Response('404'); |
283
|
|
|
} |
284
|
|
|
|
285
|
1 |
|
return new Response('OK'); |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|
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.