示例#1
0
 /**
  * @Route(
  *      "/report/drop/{correctionId}",
  *      name="innova_collecticiel_report_drop",
  *      requirements={"resourceId" = "\d+", "dropId" = "\d+", "correctionId" = "\d+"}
  * )
  * @ParamConverter("correction", class="InnovaCollecticielBundle:Correction", options={"id" = "correctionId"})
  * @ParamConverter("user", options={
  *      "authenticatedUser" = true,
  *      "messageEnabled" = true,
  *      "messageTranslationKey" = "Participate in an evaluation requires authentication. Please login.",
  *      "messageTranslationDomain" = "innova_collecticiel"
  * })
  * @Template()
  */
 public function reportDropAction(Correction $correction, User $user)
 {
     $dropzone = $correction->getDropzone();
     $drop = $correction->getDrop();
     $em = $this->getDoctrine()->getManager();
     $this->get('innova.manager.dropzone_voter')->isAllowToOpen($dropzone);
     try {
         $curent_user_correction = $em->getRepository('InnovaCollecticielBundle: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 ($this->getRequest()->isMethod('POST')) {
         $form->handleRequest($this->getRequest());
         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', [], 'innova_collecticiel'));
             $url = $this->generateUrl('innova_collecticiel_open', ['resourceId' => $dropzone->getId()]);
             return $this->redirect($url);
         }
     }
     $view = 'InnovaCollecticielBundle:Drop:reportDrop.html.twig';
     if ($this->getRequest()->isXmlHttpRequest()) {
         $view = 'InnovaCollecticielBundle:Drop:reportDropModal.html.twig';
     }
     return $this->render($view, ['workspace' => $dropzone->getResourceNode()->getWorkspace(), '_resource' => $dropzone, 'dropzone' => $dropzone, 'drop' => $drop, 'correction' => $correction, 'form' => $form->createView()]);
 }
 protected function dispatchCorrectionReportEvent(Dropzone $dropzone, Correction $correction)
 {
     $drop = $correction->getDrop();
     $rm = $this->get('claroline.manager.role_manager');
     $event = new LogCorrectionReportEvent($dropzone, $drop, $correction, $rm);
     $this->get('event_dispatcher')->dispatch('log', $event);
 }