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()) |
|
56 | |||
57 | /** |
||
58 | * Lists all tables entities. |
||
59 | */ |
||
60 | public function indexAction(Request $request) |
||
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 | 1 | ), |
|
136 | 1 | 'action' => $this->generateUrl($controller . '_create'), |
|
137 | ) |
||
138 | 1 | ); |
|
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 | 1 | ), |
|
188 | 1 | 'action' => $this->generateUrl($controller . '_create'), |
|
189 | ) |
||
190 | 1 | ); |
|
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 | 1 | ); |
|
200 | } |
||
201 | |||
202 | protected function elencoModifiche($nomebundle, $controller, $id) |
||
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 | 1 | ), |
|
247 | 1 | 'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())), |
|
248 | ) |
||
249 | 1 | ); |
|
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 | 1 | ); |
|
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 | 1 | ), |
|
298 | 1 | 'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())), |
|
299 | ) |
||
300 | 1 | ); |
|
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) |
||
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 | 1 | } 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(); |
||
419 | if ($parametritestarequest) { |
||
420 | $jsonparms = json_decode($parametritestarequest); |
||
421 | $parametritesta = get_object_vars($jsonparms); |
||
422 | $parametritesta['container'] = $container; |
||
423 | $parametritesta['doctrine'] = $em; |
||
424 | $parametritesta['request'] = $request; |
||
425 | $parametritesta['output'] = 'stampa'; |
||
426 | } |
||
427 | |||
428 | return $parametritestarequest ? $parametritesta : $paricevuti; |
||
429 | } |
||
430 | |||
431 | protected function getParametersDatiPerGriglia($request, $container, $em, $paricevuti) |
||
432 | { |
||
433 | $parametrigriglia = $request->get('parametrigriglia'); |
||
434 | if ($parametrigriglia) { |
||
435 | $jsonparms = json_decode($parametrigriglia); |
||
436 | $parametrigriglia = get_object_vars($jsonparms); |
||
437 | $parametrigriglia['container'] = $container; |
||
438 | $parametrigriglia['doctrine'] = $em; |
||
439 | $parametrigriglia['request'] = $request; |
||
440 | $parametrigriglia['output'] = 'stampa'; |
||
441 | } |
||
442 | |||
443 | return $parametrigriglia ? $parametrigriglia : $paricevuti; |
||
444 | } |
||
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.