1 | <?php |
||
10 | class FiController extends Controller |
||
11 | { |
||
12 | |||
13 | public static $namespace; |
||
14 | public static $bundle; |
||
15 | public static $controller; |
||
16 | public static $action; |
||
17 | public static $parametrigriglia; |
||
18 | |||
19 | 4 | protected function setup(Request $request) |
|
31 | |||
32 | 1 | protected function setParametriGriglia($prepar = array()) |
|
33 | { |
||
34 | 1 | $this->setup($prepar['request']); |
|
35 | 1 | $namespace = $this->getNamespace(); |
|
36 | 1 | $bundle = $this->getBundle(); |
|
37 | 1 | $controller = $this->getController(); |
|
38 | |||
39 | 1 | $gestionepermessi = $this->get("ficorebundle.gestionepermessi"); |
|
40 | 1 | $canRead = ($gestionepermessi->leggere(array('modulo' => $controller)) ? 1 : 0); |
|
41 | 1 | if (!$canRead) { |
|
42 | throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
||
43 | } |
||
44 | |||
45 | 1 | $nomebundle = $namespace . $bundle . 'Bundle'; |
|
46 | 1 | $escludi = array(); |
|
47 | |||
48 | 1 | $paricevuti = array('container' => $this->container, 'nomebundle' => $nomebundle, 'nometabella' => $controller, 'escludere' => $escludi); |
|
49 | |||
50 | 1 | if (! empty($prepar)) { |
|
51 | 1 | $paricevuti = array_merge($paricevuti, $prepar); |
|
52 | } |
||
53 | |||
54 | 1 | self::$parametrigriglia = $paricevuti; |
|
55 | 1 | } |
|
56 | |||
57 | /** |
||
58 | * Lists all tables entities. |
||
59 | */ |
||
60 | public function indexAction(Request $request) |
||
61 | { |
||
62 | /* @var $em \Doctrine\ORM\EntityManager */ |
||
63 | $this->setup($request); |
||
64 | $namespace = $this->getNamespace(); |
||
65 | $bundle = $this->getBundle(); |
||
66 | $controller = $this->getController(); |
||
67 | $container = $this->container; |
||
68 | |||
69 | $gestionepermessi = $this->get('ficorebundle.gestionepermessi'); |
||
70 | $canRead = ($gestionepermessi->leggere(array('modulo' => $controller)) ? 1 : 0); |
||
71 | if (!$canRead) { |
||
72 | throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
||
73 | } |
||
74 | $idpassato = $request->get('id'); |
||
75 | |||
76 | $nomebundle = $namespace . $bundle . 'Bundle'; |
||
77 | |||
78 | $repotabelle = $this->get('OpzioniTabella_repository'); |
||
79 | |||
80 | $paricevuti = array('nomebundle' => $nomebundle, 'nometabella' => $controller, 'container' => $container); |
||
81 | |||
82 | $testatagriglia = Griglia::testataPerGriglia($paricevuti); |
||
83 | |||
84 | $testatagriglia['multisearch'] = 1; |
||
85 | $testatagriglia['showconfig'] = 1; |
||
86 | $testatagriglia['overlayopen'] = 1; |
||
87 | |||
88 | $testatagriglia['parametritesta'] = json_encode($paricevuti); |
||
89 | |||
90 | $this->setParametriGriglia(array('request' => $request)); |
||
91 | $testatagriglia['parametrigriglia'] = json_encode(self::$parametrigriglia); |
||
92 | |||
93 | $testata = $repotabelle->editTestataFormTabelle($testatagriglia, $controller, $container); |
||
94 | return $this->render( |
||
95 | $nomebundle . ':' . $controller . ':index.html.twig', |
||
96 | array( |
||
97 | 'nomecontroller' => $controller, |
||
98 | 'testata' => $testata, |
||
99 | 'canread' => $canRead, |
||
100 | 'idpassato' => $idpassato, |
||
101 | ) |
||
102 | ); |
||
103 | } |
||
104 | |||
105 | 1 | public function grigliaAction(Request $request) |
|
112 | |||
113 | /** |
||
114 | * Creates a new table entity. |
||
115 | */ |
||
116 | 1 | public function createAction(Request $request) |
|
117 | { |
||
118 | 1 | $this->setup($request); |
|
119 | 1 | $namespace = $this->getNamespace(); |
|
120 | 1 | $bundle = $this->getBundle(); |
|
121 | 1 | $controller = $this->getController(); |
|
122 | |||
123 | 1 | $nomebundle = $namespace . $bundle . 'Bundle'; |
|
124 | 1 | $classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller; |
|
125 | 1 | $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller; |
|
126 | |||
127 | 1 | $entity = new $classbundle(); |
|
128 | 1 | $formType = $formbundle . 'Type'; |
|
129 | |||
130 | 1 | $form = $this->createForm( |
|
131 | 1 | $formType, |
|
132 | 1 | $entity, |
|
133 | array('attr' => array( |
||
134 | 1 | 'id' => 'formdati' . $controller, |
|
135 | ), |
||
136 | 1 | 'action' => $this->generateUrl($controller . '_create'), |
|
137 | ) |
||
138 | ); |
||
139 | |||
140 | 1 | $form->submit($request->request->get($form->getName())); |
|
141 | |||
142 | 1 | if ($form->isValid()) { |
|
143 | 1 | $em = $this->getDoctrine()->getManager(); |
|
144 | 1 | $em->persist($entity); |
|
145 | 1 | $em->flush(); |
|
146 | |||
147 | 1 | $continua = $request->get('continua'); |
|
148 | 1 | if ($continua == 0) { |
|
149 | 1 | return new Response('OK'); |
|
150 | } else { |
||
151 | return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $entity->getId()))); |
||
152 | } |
||
153 | } |
||
154 | |||
155 | return $this->render( |
||
156 | $nomebundle . ':' . $controller . ':new.html.twig', |
||
157 | array( |
||
158 | 'nomecontroller' => $controller, |
||
159 | 'entity' => $entity, |
||
160 | 'form' => $form->createView(), |
||
161 | ) |
||
162 | ); |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * Displays a form to create a new table entity. |
||
167 | */ |
||
168 | 1 | public function newAction(Request $request) |
|
169 | { |
||
170 | 1 | $this->setup($request); |
|
171 | 1 | $namespace = $this->getNamespace(); |
|
172 | 1 | $bundle = $this->getBundle(); |
|
173 | 1 | $controller = $this->getController(); |
|
174 | |||
175 | 1 | $nomebundle = $namespace . $bundle . 'Bundle'; |
|
176 | 1 | $classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller; |
|
177 | 1 | $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller; |
|
178 | 1 | $formType = $formbundle . 'Type'; |
|
179 | |||
180 | 1 | $entity = new $classbundle(); |
|
181 | |||
182 | 1 | $form = $this->createForm( |
|
183 | 1 | $formType, |
|
184 | 1 | $entity, |
|
185 | array('attr' => array( |
||
186 | 1 | 'id' => 'formdati' . $controller, |
|
187 | ), |
||
188 | 1 | 'action' => $this->generateUrl($controller . '_create'), |
|
189 | ) |
||
190 | ); |
||
191 | |||
192 | 1 | return $this->render( |
|
193 | 1 | $nomebundle . ':' . $controller . ':new.html.twig', |
|
194 | array( |
||
195 | 1 | 'nomecontroller' => $controller, |
|
196 | 1 | 'entity' => $entity, |
|
197 | 1 | 'form' => $form->createView(), |
|
198 | ) |
||
199 | ); |
||
200 | } |
||
201 | |||
202 | protected function elencoModifiche($nomebundle, $controller, $id) |
||
|
|||
203 | { |
||
204 | $controllerStorico = 'Storicomodifiche'; |
||
205 | $em = $this->getDoctrine()->getManager(); |
||
206 | $risultato = $em->getRepository('FiCoreBundle:' . $controllerStorico)->findBy( |
||
207 | array( |
||
208 | 'nometabella' => $controller, |
||
209 | 'idtabella' => $id, |
||
210 | ) |
||
211 | ); |
||
212 | |||
213 | return $risultato; |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * Displays a form to edit an existing table entity. |
||
218 | */ |
||
219 | 1 | public function editAction(Request $request, $id) |
|
220 | { |
||
221 | /* @var $em \Doctrine\ORM\EntityManager */ |
||
222 | 1 | $this->setup($request); |
|
223 | 1 | $namespace = $this->getNamespace(); |
|
224 | 1 | $bundle = $this->getBundle(); |
|
225 | 1 | $controller = $this->getController(); |
|
226 | |||
227 | 1 | $nomebundle = $namespace . $bundle . 'Bundle'; |
|
228 | 1 | $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller; |
|
229 | 1 | $formType = $formbundle . 'Type'; |
|
230 | |||
231 | 1 | $elencomodifiche = $this->elencoModifiche($nomebundle, $controller, $id); |
|
232 | |||
233 | 1 | $em = $this->getDoctrine()->getManager(); |
|
234 | |||
235 | 1 | $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id); |
|
236 | |||
237 | 1 | if (!$entity) { |
|
238 | throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.'); |
||
239 | } |
||
240 | |||
241 | 1 | $editForm = $this->createForm( |
|
242 | 1 | $formType, |
|
243 | 1 | $entity, |
|
244 | array('attr' => array( |
||
245 | 1 | 'id' => 'formdati' . $controller, |
|
246 | ), |
||
247 | 1 | 'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())), |
|
248 | ) |
||
249 | ); |
||
250 | |||
251 | 1 | $deleteForm = $this->createDeleteForm($id); |
|
252 | |||
253 | 1 | return $this->render( |
|
254 | 1 | $nomebundle . ':' . $controller . ':edit.html.twig', |
|
255 | array( |
||
256 | 1 | 'entity' => $entity, |
|
257 | 1 | 'nomecontroller' => $controller, |
|
258 | 1 | 'edit_form' => $editForm->createView(), |
|
259 | 1 | 'delete_form' => $deleteForm->createView(), |
|
260 | 1 | 'elencomodifiche' => $elencomodifiche, |
|
261 | ) |
||
262 | ); |
||
263 | } |
||
264 | |||
265 | /** |
||
266 | * Edits an existing table entity. |
||
267 | */ |
||
268 | 1 | public function updateAction(Request $request, $id) |
|
269 | { |
||
270 | /* @var $em \Doctrine\ORM\EntityManager */ |
||
271 | 1 | $this->setup($request); |
|
272 | 1 | $namespace = $this->getNamespace(); |
|
273 | 1 | $bundle = $this->getBundle(); |
|
274 | 1 | $controller = $this->getController(); |
|
275 | |||
276 | 1 | $nomebundle = $namespace . $bundle . 'Bundle'; |
|
277 | 1 | $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller; |
|
278 | 1 | $formType = $formbundle . 'Type'; |
|
279 | |||
280 | 1 | $repoStorico = $this->container->get('Storicomodifiche_repository'); |
|
281 | |||
282 | 1 | $em = $this->getDoctrine()->getManager(); |
|
283 | |||
284 | 1 | $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id); |
|
285 | |||
286 | 1 | if (!$entity) { |
|
287 | throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.'); |
||
288 | } |
||
289 | |||
290 | 1 | $deleteForm = $this->createDeleteForm($id); |
|
291 | |||
292 | 1 | $editForm = $this->createForm( |
|
293 | 1 | $formType, |
|
294 | 1 | $entity, |
|
295 | array('attr' => array( |
||
296 | 1 | 'id' => 'formdati' . $controller, |
|
297 | ), |
||
298 | 1 | 'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())), |
|
299 | ) |
||
300 | ); |
||
301 | |||
302 | 1 | $editForm->submit($request->request->get($editForm->getName())); |
|
303 | |||
304 | 1 | if ($editForm->isValid()) { |
|
305 | 1 | $originalData = $em->getUnitOfWork()->getOriginalEntityData($entity); |
|
306 | |||
307 | 1 | $em->persist($entity); |
|
308 | 1 | $em->flush(); |
|
309 | |||
310 | 1 | $newData = $em->getUnitOfWork()->getOriginalEntityData($entity); |
|
311 | 1 | $changes = $repoStorico->isRecordChanged($nomebundle, $controller, $originalData, $newData); |
|
312 | |||
313 | 1 | if ($changes) { |
|
314 | $repoStorico->saveHistory($controller, $changes, $id, $this->getUser()); |
||
315 | } |
||
316 | |||
317 | 1 | $continua = $request->get('continua'); |
|
318 | 1 | if ($continua == 0) { |
|
319 | 1 | return new Response('OK'); |
|
320 | } else { |
||
321 | return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $id))); |
||
322 | } |
||
323 | } |
||
324 | |||
325 | return $this->render( |
||
326 | $nomebundle . ':' . $controller . ':edit.html.twig', |
||
327 | array( |
||
328 | 'entity' => $entity, |
||
329 | 'edit_form' => $editForm->createView(), |
||
330 | 'delete_form' => $deleteForm->createView(), |
||
331 | 'nomecontroller' => $controller, |
||
332 | ) |
||
333 | ); |
||
334 | } |
||
335 | |||
336 | /** |
||
337 | * Edits an existing table entity. |
||
338 | */ |
||
339 | public function aggiornaAction(Request $request) |
||
340 | { |
||
341 | /* @var $em \Doctrine\ORM\EntityManager */ |
||
342 | $this->setup($request); |
||
343 | $namespace = $this->getNamespace(); |
||
344 | $bundle = $this->getBundle(); |
||
345 | $controller = $this->getController(); |
||
346 | |||
347 | $nomebundle = $namespace . $bundle . 'Bundle'; |
||
348 | |||
349 | $id = $this->get('request')->request->get('id'); |
||
350 | |||
351 | $em = $this->getDoctrine()->getManager(); |
||
352 | |||
353 | $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id); |
||
354 | |||
355 | if (!$entity) { |
||
356 | throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.'); |
||
357 | } |
||
358 | |||
359 | throw $this->createNotFoundException("Implementare a seconda dell'esigenza 'aggiornaAction' del controller " |
||
360 | . $nomebundle |
||
361 | . '/' |
||
362 | . $controller); |
||
363 | } |
||
364 | |||
365 | /** |
||
366 | * Deletes a table entity. |
||
367 | */ |
||
368 | 1 | public function deleteAction(Request $request) |
|
369 | { |
||
370 | /* @var $em \Doctrine\ORM\EntityManager */ |
||
371 | 1 | $this->setup($request); |
|
372 | 1 | $namespace = $this->getNamespace(); |
|
373 | 1 | $bundle = $this->getBundle(); |
|
374 | 1 | $controller = $this->getController(); |
|
375 | |||
376 | 1 | $nomebundle = $namespace . $bundle . 'Bundle'; |
|
377 | |||
378 | //if (!$request->isXmlHttpRequest()) { |
||
379 | // $request->checkCSRFProtection(); |
||
380 | //} |
||
381 | try { |
||
382 | 1 | $em = $this->getDoctrine()->getManager(); |
|
383 | 1 | $qb = $em->createQueryBuilder(); |
|
384 | 1 | $ids = explode(',', $request->get('id')); |
|
385 | 1 | $qb->delete($nomebundle . ':' . $controller, 'u') |
|
386 | 1 | ->andWhere('u.id IN (:ids)') |
|
387 | 1 | ->setParameter('ids', $ids); |
|
388 | |||
389 | 1 | $query = $qb->getQuery(); |
|
390 | 1 | $query->execute(); |
|
391 | } catch (\Exception $e) { |
||
392 | $response = new Response(); |
||
393 | $response->setStatusCode('200'); |
||
394 | |||
395 | return new Response('404'); |
||
396 | } |
||
397 | |||
398 | 1 | return new Response('OK'); |
|
399 | } |
||
400 | |||
401 | /** |
||
402 | * Creates a form to delete a table entity by id. |
||
403 | * |
||
404 | * @param mixed $id The entity id |
||
405 | * |
||
406 | * @return \Symfony\Component\Form\Form The form |
||
407 | */ |
||
408 | protected function createDeleteForm($id) |
||
414 | |||
415 | protected function getParametersTestataPerGriglia($request, $container, $em, $paricevuti) |
||
416 | { |
||
417 | $parametritestarequest = $request->get('parametritesta'); |
||
418 | $parametritesta = array(); |
||
430 | |||
431 | protected function getParametersDatiPerGriglia($request, $container, $em, $paricevuti) |
||
445 | |||
446 | 4 | protected function getNamespace() |
|
450 | |||
451 | 4 | protected function getBundle() |
|
455 | |||
456 | 4 | protected function getController() |
|
460 | |||
461 | protected function getAction() |
||
465 | } |
||
466 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.