/**
  * @param Dropzone $dropzone
  * @param Drop     $drop
  * @param Document $document
  */
 public function __construct(Dropzone $dropzone, Drop $drop, Document $document)
 {
     $documentsDetails = array();
     foreach ($drop->getDocuments() as $document) {
         $documentsDetails[] = $document->toArray();
     }
     $details = array('dropzone' => array('id' => $dropzone->getId()), 'drop' => array('id' => $drop->getId(), 'documents' => $documentsDetails), 'document' => $document->toArray());
     parent::__construct($dropzone->getResourceNode(), $details);
 }
 /**
  * @param Wiki         $wiki
  * @param Section      $section
  * @param Contribution $contribution
  */
 public function __construct(Document $document, Dropzone $dropzone, $userIds)
 {
     $this->document = $document;
     $this->dropzone = $dropzone;
     $this->type = $dropzone->getResourceNode()->getName();
     $this->userIds = $userIds;
     $this->details = array();
     // Récupération du nom et du prénom
     $this->firstName = $document->getSender()->getFirstName();
     $this->lastName = $document->getSender()->getLastName();
     parent::__construct($dropzone->getResourceNode(), $this->details);
 }
 /**
  * @ParamConverter("gradingNotation", class="InnovaCollecticielBundle:GradingNotation", options={"id" = "gradingNotationId"})
  * @ParamConverter("document", class="InnovaCollecticielBundle:Document", options={"id" = "documentId"})
  * @ParamConverter("dropzone", class="InnovaCollecticielBundle:Dropzone", options={"id" = "dropzoneId"})
  * @Template()
  */
 public function renderChoiceTextAction(GradingNotation $gradingNotation, Document $document, Dropzone $dropzone)
 {
     $choiceText = '';
     // Appel pour accés base
     $em = $this->getDoctrine()->getManager();
     // Ajout pour avoir si la notation a été transmise ou pas.
     $notationArray = $em->getRepository('InnovaCollecticielBundle:Notation')->findBy(['document' => $document->getId(), 'dropzone' => $dropzone->getId()]);
     // Nombre de notation pour le document et pour le dropzone
     $countNotation = count($notationArray);
     if ($countNotation !== 0) {
         $choiceTextArray = $em->getRepository('InnovaCollecticielBundle:ChoiceNotation')->getChoiceTextForCriteriaAndNotation($gradingNotation, $notationArray[0]);
         if (!empty($choiceTextArray)) {
             // Récupération de la valeur du texte
             $choiceText = $choiceTextArray[0]->getChoiceText();
         }
     }
     return ['value' => $choiceText];
 }
 /**
  * @param Wiki $wiki
  * @param Section $section
  * @param Contribution $contribution
  */
 public function __construct(Document $document, Dropzone $dropzone, $userIds)
 {
     //        $this->resourceNodeId = $dropzone->getDrops()[0]->getUser()->getId();
     //        $dropId = $document->getDrop()->getId(); //->getDropzone()->getId();
     //var_dump($dp);
     //var_dump($document);die();
     $this->document = $document;
     $this->type = $dropzone->getResourceNode()->getName();
     $this->userIds = $userIds;
     //echo "<pre>";
     //var_dump($this->userIds);
     //echo "</pre>";
     //die();
     $this->details = array();
     // Récupération du nom et du prénom
     $this->firstName = $document->getSender()->getFirstName();
     $this->lastName = $document->getSender()->getLastName();
     //var_dump($this->firstName);
     //var_dump($this->lastName);
     //var_dump($this->type);
     //die();
     parent::__construct($dropzone->getResourceNode(), $this->details);
 }
 /**
  * @param Wiki         $wiki
  * @param Section      $section
  * @param Contribution $contribution
  */
 public function __construct(Document $document, Dropzone $dropzone, $userIds)
 {
     $this->document = $document;
     // Traitement du paramètre "type" : gestion du cas spécifique du type URL.
     if ($document->getType() == 'url') {
         $this->type = $document->getUrl();
     } elseif (strlen($document->getTitle()) > 0) {
         $this->type = $document->getTitle();
     } else {
         $this->type = $document->getResourceNode()->getName();
     }
     $this->userIds = $userIds;
     $this->details = array();
     // Récupération du nom et du prénom
     $this->firstName = $document->getSender()->getFirstName();
     $this->lastName = $document->getSender()->getLastName();
     parent::__construct($dropzone->getResourceNode(), $this->details);
 }
 /**
  * @param Dropzone $dropzone
  * @param Drop     $drop
  * @param Document $document
  */
 public function __construct(Dropzone $dropzone, Drop $drop, Document $document)
 {
     $details = array('dropzone' => array('id' => $dropzone->getId()), 'drop' => array('id' => $drop->getId(), 'owner' => array('id' => $drop->getUser()->getId(), 'lastName' => $drop->getUser()->getLastName(), 'firstName' => $drop->getUser()->getFirstName(), 'username' => $drop->getUser()->getUsername())), 'document' => $document->toArray());
     parent::__construct($dropzone->getResourceNode(), $details);
 }
 /**
  * @Route(
  *      "/undocument/{documentId}",
  *      name="innova_collecticiel_unvalidate_document",
  *      requirements={"documentId" = "\d+"},
  *      options={"expose"=true}
  * )
  * @ParamConverter("document", class="InnovaCollecticielBundle:Document", options={"id" = "documentId"})
  * @Template()
  */
 public function ajaxUnvalidateDocumentAction(Document $document)
 {
     // Appel pour accés base
     $em = $this->getDoctrine()->getManager();
     // Recherche en base des données du document à mettre à jour
     $doc = $this->getDoctrine()->getRepository('InnovaCollecticielBundle:Document')->find($document->getId());
     // Mise à jour du booléen de Validation de true à false
     $doc->setvalidate(false);
     // Mise à jour de la base de données
     $em->persist($doc);
     $em->flush();
     // Récupération du dropID puis du dropZone
     $dropId = $document->getDrop()->getId();
     $dropRepo = $this->getDoctrine()->getRepository('InnovaCollecticielBundle:Drop');
     $drops = $dropRepo->findBy(array('id' => $dropId));
     $dropzoneRepo = $this->getDoctrine()->getRepository('InnovaCollecticielBundle:DropZone');
     $dropzones = $dropzoneRepo->findBy(array('id' => $drops[0]->getDropzone()->getId()));
     $dropzoneManager = $this->get('innova.manager.dropzone_manager');
     $collecticielOpenOrNot = $dropzoneManager->collecticielOpenOrNot($dropzones[0]);
     // Ajout afin d'afficher la partie du code avec "Demande transmise"
     $template = $this->get("templating")->render('InnovaCollecticielBundle:Document:documentIsValidate.html.twig', array('document' => $document, 'collecticielOpenOrNot' => $collecticielOpenOrNot, 'dropzone' => $dropzones[0]));
     // Retour du template actualisé à l'Ajax et non plus du Json.
     return new Response($template);
 }
 /**
  * @Route(
  *      "/{resourceId}/drops/detail/correction/{state}/{correctionId}/document/{documentId}",
  *      name="innova_collecticiel_drops_detail_comment",
  *      requirements={"documentId" = "\d+", "resourceId" = "\d+", "correctionId" = "\d+", "state" = "show|edit|preview"},
  *      defaults={"page" = 1}
  * )
  * @Route(
  *      "/{resourceId}/drops/detail/correction/{state}/{correctionId}/{page}",
  *      name="innova_collecticiel_drops_detail_correction_paginated",
  *      requirements={"resourceId" = "\d+", "correctionId" = "\d+", "page" = "\d+", "state" = "show|edit|preview"}
  * )
  * @ParamConverter("dropzone", class="InnovaCollecticielBundle:Dropzone", options={"id" = "resourceId"})
  * @ParamConverter("document", class="InnovaCollecticielBundle:Document", options={"id" = "documentId"})
  * @ParamConverter("user", options={
  *      "authenticatedUser" = true,
  *      "messageEnabled" = true,
  *      "messageTranslationKey" = "Correct an evaluation requires authentication. Please login.",
  *      "messageTranslationDomain" = "innova_collecticiel"
  * })
  * @Template()
  */
 public function dropsDetailCommentAction(Dropzone $dropzone, $state, $correctionId, $page, User $user, Document $document)
 {
     $documentOri = new Document();
     $documentOri = $document;
     $em = $this->getDoctrine()->getManager();
     $this->get('innova.manager.dropzone_voter')->isAllowToOpen($dropzone);
     $correction = $this->getDoctrine()->getRepository('InnovaCollecticielBundle:Correction')->getCorrectionAndDropAndUserAndDocuments($dropzone, $correctionId);
     $countCorrection = count($correction);
     // Parcours des documents sélectionnés
     foreach ($correction->getDrop()->getDocuments() as $document) {
         if ($document->getId() == $documentOri->getId()) {
             $documentId = $document->getId();
             // Ajout pour avoir les commentaires et qui les a lu.
             // Lire les commentaires et les passer à la vue
             $comments = $this->getDoctrine()->getRepository('InnovaCollecticielBundle:Comment')->findBy(array('document' => $documentId));
             // Parcours des commentaires des documents sélectionnés
             foreach ($comments as $comment) {
                 $commentId = $comment->getId();
                 //                echo "Comment = " . $commentId . " - " . $correction->getUser()->getId();
                 $comments_read = $this->getDoctrine()->getRepository('InnovaCollecticielBundle:CommentRead')->findBy(array('comment' => $commentId, 'user' => $correction->getUser()->getId()));
                 // Nombre de lectures du commentaire pour cet utilisateur pour ce commentaire du document
                 $countCommentRead = count($comments_read);
                 //                    $countCommentRead = 0; // Pour les tests, à enlever
                 // Ce commentaire n'avait pas été lu.
                 // Donc, maintenant, il va l'être,
                 // je dois donc insérer une occurrence dans la table CommentRead";
                 if ($countCommentRead == 0) {
                     $comment_read_add = new CommentRead();
                     $comment_read_add->setComment($comment);
                     $comment_read_add->setUser($user);
                     $em->persist($comment_read_add);
                     $unitOfWork = $em->getUnitOfWork();
                     $unitOfWork->computeChangeSets();
                     $dropzoneChangeSet = $unitOfWork->getEntityChangeSet($dropzone);
                     $event = new LogCommentReadCreateEvent($dropzone, $dropzoneChangeSet, $comment_read_add);
                     $this->dispatch($event);
                 }
             }
             $em->flush();
             // Fin ajout.
         }
     }
     $userId = $this->get('security.token_storage')->getToken()->getUser()->getId();
     if ($state == 'preview') {
         if ($correction->getDrop()->getUser()->getId() != $userId) {
             throw new AccessDeniedException();
         }
     } else {
         //            $this->get('innova.manager.dropzone_voter')->isAllowToEdit($dropzone);
     }
     //$this->checkUserGradeAvailable($dropzone);
     /*
     if (!$dropzone->getPeerReview()) {
         return $this->redirect(
             $this->generateUrl(
                 'innova_collecticiel_drops_detail_correction_standard',
                 array(
                     'resourceId' => $dropzone->getId(),
                     'state' => $state,
                     'correctionId' => $correctionId
                 )
             )
         );
     }
     */
     /** @var Correction $correction */
     $edit = $state == 'edit';
     if ($correction == null) {
         throw new NotFoundHttpException();
     }
     if ($edit === true and $correction->getEditable() === false) {
         throw new AccessDeniedException();
     }
     $em = $this->getDoctrine()->getManager();
     $pager = $this->getCriteriaPager($dropzone);
     try {
         $pager->setCurrentPage($page);
     } catch (NotValidCurrentPageException $e) {
         throw new NotFoundHttpException();
     }
     $oldData = array();
     $grades = array();
     if ($correction !== null) {
         $grades = $em->getRepository('InnovaCollecticielBundle:Grade')->findByCriteriaAndCorrection($pager->getCurrentPageResults(), $correction);
         foreach ($grades as $grade) {
             $oldData[$grade->getCriterion()->getId()] = $grade->getValue() >= $dropzone->getTotalCriteriaColumn() ? $dropzone->getTotalCriteriaColumn() - 1 : $grade->getValue();
         }
     }
     $formComment = $this->createForm(new CommentType(new Comment(), null));
     $form = $this->createForm(new CorrectionCriteriaPageType(), $oldData, array('edit' => $edit, 'criteria' => $pager->getCurrentPageResults(), 'totalChoice' => $dropzone->getTotalCriteriaColumn()));
     if ($edit) {
         if ($this->getRequest()->isMethod('POST') and $correction !== null) {
             $form->handleRequest($this->getRequest());
             if ($form->isValid()) {
                 $data = $form->getData();
                 foreach ($data as $criterionId => $value) {
                     $this->persistGrade($grades, $criterionId, $value, $correction);
                 }
                 if ($correction->getFinished()) {
                     $totalGrade = $this->get('innova.manager.correction_manager')->calculateCorrectionTotalGrade($dropzone, $correction);
                     $correction->setTotalGrade($totalGrade);
                     $em->persist($correction);
                     $em->flush();
                 }
                 $goBack = $form->get('goBack')->getData();
                 if ($goBack == 1) {
                     $pageNumber = max($page - 1, 0);
                     return $this->redirect($this->generateUrl('innova_collecticiel_drops_detail_correction_paginated', array('resourceId' => $dropzone->getId(), 'state' => 'edit', 'correctionId' => $correction->getId(), 'page' => $pageNumber)));
                 } else {
                     if ($pager->getCurrentPage() < $pager->getNbPages()) {
                         return $this->redirect($this->generateUrl('innova_collecticiel_drops_detail_correction_paginated', array('resourceId' => $dropzone->getId(), 'state' => 'edit', 'correctionId' => $correction->getId(), 'page' => $page + 1)));
                     } else {
                         return $this->redirect($this->generateUrl('innova_collecticiel_drops_detail_correction_comment', array('resourceId' => $dropzone->getId(), 'state' => 'edit', 'correctionId' => $correction->getId())));
                     }
                 }
             }
         }
     }
     // Appel de la vue qui va gérer l'ajout des commentaires. InnovaERV.
     $view = 'InnovaCollecticielBundle:Correction:correctCriteria.html.twig';
     if ($state == 'show' || $state == 'edit') {
         return $this->render($view, array('workspace' => $dropzone->getResourceNode()->getWorkspace(), '_resource' => $dropzone, 'dropzone' => $dropzone, 'correction' => $correction, 'pager' => $pager, 'form' => $form->createView(), 'formComment' => $formComment->createView(), 'admin' => true, 'edit' => $edit, 'state' => $state, 'document' => $documentOri, 'comments' => $comments, 'user' => $user));
     } else {
         if ($state == 'preview') {
             return $this->render($view, array('workspace' => $dropzone->getResourceNode()->getWorkspace(), '_resource' => $dropzone, 'dropzone' => $dropzone, 'correction' => $correction, 'pager' => $pager, 'form' => $form->createView(), 'formComment' => $formComment->createView(), 'admin' => false, 'edit' => false, 'state' => $state));
         }
     }
 }
 /**
  * @Route(
  *      "/document/{documentId}",
  *      name="innova_collecticiel_validate_document",
  *      requirements={"documentId" = "\d+"},
  *      options={"expose"=true}
  * )
  * @ParamConverter("document", class="InnovaCollecticielBundle:Document", options={"id" = "documentId"})
  * @Template()
  */
 public function ajaxValidateDocumentAction(Document $document)
 {
     // Appel pour accés base
     $em = $this->getDoctrine()->getManager();
     // Recherche en base des données du document à mettre à jour
     $doc = $this->getDoctrine()->getRepository('InnovaCollecticielBundle:Document')->find($document->getId());
     // Mise à jour du booléen de Validation de false à true
     $doc->setvalidate(true);
     // Mise à jour de la base de données
     $em->persist($doc);
     $em->flush();
     // Ajout afin d'afficher la partie du code avec "Demande transmise"
     $template = $this->get("templating")->render('InnovaCollecticielBundle:Document:documentIsValidate.html.twig', array('document' => $document));
     // Retour du template actualisé à l'Ajax et non plus du Json.
     return new Response($template);
 }