/** * @Route( * "/{resourceId}/delete/correction/{correctionId}/{backPage}", * name="innova_collecticiel_drops_detail_delete_correction", * requirements={"resourceId" = "\d+", "correctionId" = "\d+"}, * defaults={"backPage" = "default"} * ) * @ParamConverter("dropzone", class="InnovaCollecticielBundle:Dropzone", options={"id" = "resourceId"}) * @ParamConverter("correction", class="InnovaCollecticielBundle:Correction", options={"id" = "correctionId"}) * @Template() */ public function deleteCorrectionAction(Dropzone $dropzone, Correction $correction, $backPage) { $userId = $correction->getUser()->getId(); $this->get('innova.manager.dropzone_voter')->isAllowToOpen($dropzone); $this->get('innova.manager.dropzone_voter')->isAllowToEdit($dropzone); if ($correction->getEditable() === false) { throw new AccessDeniedException(); } $dropId = $correction->getDrop()->getId(); // Action on POST , real delete if ($this->getRequest()->isMethod('POST')) { $em = $this->getDoctrine()->getManager(); $em->remove($correction); $em->flush(); $event = new LogCorrectionDeleteEvent($dropzone, $correction->getDrop(), $correction); $this->dispatch($event); $return = null; if ($backPage == "AdminCorrectionsByUser") { $return = $this->redirect($this->generateUrl('innova_collecticiel_drops_detail', array('resourceId' => $dropzone->getId(), 'dropId' => $dropId))); } else { $return = $this->redirect($this->generateUrl('innova_collecticiel_examiner_corrections', array('resourceId' => $dropzone->getId(), 'userId' => $userId))); } } else { // Action on GET , Ask confirmation Modal or not. $view = 'InnovaCollecticielBundle:Correction:deleteCorrection.html.twig'; $backUserId = 0; $backUserId = $this->getRequest()->get('backUserId'); if ($this->getRequest()->isXmlHttpRequest()) { $view = 'InnovaCollecticielBundle:Correction:deleteCorrectionModal.html.twig'; $backUserId = $correction->getUser()->getId(); } $return = $this->render($view, array('workspace' => $dropzone->getResourceNode()->getWorkspace(), '_resource' => $dropzone, 'dropzone' => $dropzone, 'correction' => $correction, 'drop' => $correction->getDrop(), 'backPage' => 'AdminCorrectionsByUser', 'backUserId' => $backUserId)); } return $return; }