コード例 #1
0
 /**
  * @Route(
  *      "/{resourceId}/delete/correction/{correctionId}/{backPage}",
  *      name="icap_dropzone_drops_detail_delete_correction",
  *      requirements={"resourceId" = "\d+", "correctionId" = "\d+"},
  *      defaults={"backPage" = "default"}
  * )
  * @ParamConverter("dropzone", class="IcapDropzoneBundle:Dropzone", options={"id" = "resourceId"})
  * @ParamConverter("correction", class="IcapDropzoneBundle:Correction", options={"id" = "correctionId"})
  * @Template()
  */
 public function deleteCorrectionAction(Request $request, Dropzone $dropzone, Correction $correction, $backPage)
 {
     $userId = $correction->getUser()->getId();
     $this->get('icap.manager.dropzone_voter')->isAllowToOpen($dropzone);
     $this->get('icap.manager.dropzone_voter')->isAllowToEdit($dropzone);
     if ($correction->getEditable() === false) {
         throw new AccessDeniedException();
     }
     $dropId = $correction->getDrop()->getId();
     // Action on POST , real delete
     if ($request->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('icap_dropzone_drops_detail', array('resourceId' => $dropzone->getId(), 'dropId' => $dropId)));
         } else {
             $return = $this->redirect($this->generateUrl('icap_dropzone_examiner_corrections', array('resourceId' => $dropzone->getId(), 'userId' => $userId)));
         }
     } else {
         // Action on GET , Ask confirmation Modal or not.
         $view = 'IcapDropzoneBundle:Correction:deleteCorrection.html.twig';
         $backUserId = 0;
         $backUserId = $request->get('backUserId');
         if ($request->isXmlHttpRequest()) {
             $view = 'IcapDropzoneBundle: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;
 }