コード例 #1
0
 /**
  * @Route(
  *      "/report/drop/{correctionId}",
  *      name="icap_dropzone_report_drop",
  *      requirements={"resourceId" = "\d+", "dropId" = "\d+", "correctionId" = "\d+"}
  * )
  * @ParamConverter("correction", class="IcapDropzoneBundle:Correction", options={"id" = "correctionId"})
  * @ParamConverter("user", options={
  *      "authenticatedUser" = true,
  *      "messageEnabled" = true,
  *      "messageTranslationKey" = "Participate in an evaluation requires authentication. Please login.",
  *      "messageTranslationDomain" = "icap_dropzone"
  * })
  * @Template()
  */
 public function reportDropAction(Request $request, Correction $correction, User $user)
 {
     $dropzone = $correction->getDropzone();
     $drop = $correction->getDrop();
     $em = $this->getDoctrine()->getManager();
     $this->get('icap.manager.dropzone_voter')->isAllowToOpen($dropzone);
     try {
         $curent_user_correction = $em->getRepository('IcapDropzoneBundle:Correction')->getNotFinished($dropzone, $user);
     } catch (NotFoundHttpException $e) {
         throw new AccessDeniedException();
     }
     if ($curent_user_correction === null || $curent_user_correction->getId() !== $correction->getId()) {
         throw new AccessDeniedException();
     }
     $form = $this->createForm(new CorrectionReportType(), $correction);
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $drop->setReported(true);
             $correction->setReporter(true);
             $correction->setEndDate(new \DateTime());
             $correction->setFinished(true);
             $correction->setTotalGrade(0);
             $em->persist($drop);
             $em->persist($correction);
             $em->flush();
             $this->dispatchDropReportEvent($dropzone, $drop, $correction);
             $this->getRequest()->getSession()->getFlashBag()->add('success', $this->get('translator')->trans('Your report has been saved', [], 'icap_dropzone'));
             return $this->redirect($this->generateUrl('icap_dropzone_open', ['resourceId' => $dropzone->getId()]));
         }
     }
     $view = 'IcapDropzoneBundle:Drop:reportDrop.html.twig';
     if ($request->isXmlHttpRequest()) {
         $view = 'IcapDropzoneBundle:Drop:reportDropModal.html.twig';
     }
     return $this->render($view, ['workspace' => $dropzone->getResourceNode()->getWorkspace(), '_resource' => $dropzone, 'dropzone' => $dropzone, 'drop' => $drop, 'correction' => $correction, 'form' => $form->createView()]);
 }