/** * Returns whether a hint is related to a paper. * * @param Paper $paper * @param Hint $hint * * @return bool */ public function hasHint(Paper $paper, Hint $hint) { $qb = $this->createQueryBuilder('p'); $count = $qb->select('COUNT(p)')->join('p.exercise', 'e')->join('e.steps', 's')->join('s.stepQuestions', 'sq')->where('e = :exercise')->andWhere('sq.question = :question')->setParameters(['question' => $hint->getQuestion(), 'exercise' => $paper->getExercise()])->getQuery()->getSingleScalarResult(); return 0 < $count; }
/** * For the navigation in a paper * Finds and displays the question selectionned by the User in an assesment * * @access private * * @param integer $numQuestionToDisplayed position of the question in the paper * @param \UJM\ExoBundle\Entity\Interaction $interactionToDisplay interaction (question) to displayed * @param String $typeInterToDisplayed * @param boolean $dispButtonInterrupt to display or no the button "Interrupt" * @param integer $maxAttempsAllowed the number of max attemps allowed for the exercise * @param Claroline workspace $workspace * @param \UJM\ExoBundle\Entity\Paper $paper current paper * * @return \Symfony\Component\HttpFoundation\Response */ private function displayQuestion($numQuestionToDisplayed, $interactionToDisplay, $typeInterToDisplayed, $dispButtonInterrupt, $maxAttempsAllowed, $workspace, $paper) { $em = $this->getDoctrine()->getManager(); $session = $this->getRequest()->getSession(); $tabOrderInter = $session->get('tabOrderInter'); switch ($typeInterToDisplayed) { case "InteractionQCM": $interactionToDisplayed = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:InteractionQCM')->getInteractionQCM($interactionToDisplay->getId()); if ($interactionToDisplayed[0]->getShuffle()) { $interactionToDisplayed[0]->shuffleChoices(); } else { $interactionToDisplayed[0]->sortChoices(); } $responseGiven = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Response')->getAlreadyResponded($session->get('paper'), $interactionToDisplay->getId()); if (count($responseGiven) > 0) { $responseGiven = $responseGiven[0]->getResponse(); } else { $responseGiven = ''; } break; case "InteractionGraphic": $interactionToDisplayed = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:InteractionGraphic')->getInteractionGraphic($interactionToDisplay->getId()); $coords = $em->getRepository('UJMExoBundle:Coords')->findBy(array('interactionGraphic' => $interactionToDisplayed[0]->getId())); $responseGiven = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Response')->getAlreadyResponded($session->get('paper'), $interactionToDisplay->getId()); if (count($responseGiven) > 0) { $responseGiven = $responseGiven[0]->getResponse(); } else { $responseGiven = ''; } $array['listCoords'] = $coords; break; case "InteractionHole": $interactionToDisplayed = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:InteractionHole')->getInteractionHole($interactionToDisplay->getId()); $responseGiven = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Response')->getAlreadyResponded($session->get('paper'), $interactionToDisplay->getId()); if (count($responseGiven) > 0) { $responseGiven = $responseGiven[0]->getResponse(); } else { $responseGiven = ''; } break; case "InteractionOpen": $interactionToDisplayed = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:InteractionOpen')->getInteractionOpen($interactionToDisplay->getId()); $responseGiven = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Response')->getAlreadyResponded($session->get('paper'), $interactionToDisplay->getId()); if (count($responseGiven) > 0) { $responseGiven = $responseGiven[0]->getResponse(); } else { $responseGiven = ''; } break; case "InteractionMatching": $interactionToDisplayed = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:InteractionMatching')->getInteractionMatching($interactionToDisplay->getId()); if ($interactionToDisplayed[0]->getShuffle()) { $interactionToDisplayed[0]->shuffleProposals(); $interactionToDisplayed[0]->shuffleLabels(); } else { $interactionToDisplayed[0]->sortProposals(); $interactionToDisplayed[0]->sortLabels(); } $responseMatch = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Response')->getAlreadyResponded($session->get('paper'), $interactionToDisplay->getId()); if (count($responseMatch) > 0) { $responseGiven = $this->container->get('ujm.exercise_services')->getTabResponseIndex($responseMatch[0]->getResponse()); } else { $responseGiven = ''; } break; } $array['workspace'] = $workspace; $array['tabOrderInter'] = $tabOrderInter; $array['interactionToDisplayed'] = $interactionToDisplayed[0]; $array['interactionType'] = $typeInterToDisplayed; $array['numQ'] = $numQuestionToDisplayed; $array['paper'] = $session->get('paper'); $array['numAttempt'] = $paper->getNumPaper(); $array['response'] = $responseGiven; $array['dispButtonInterrupt'] = $dispButtonInterrupt; $array['maxAttempsAllowed'] = $maxAttempsAllowed; $array['_resource'] = $paper->getExercise(); return $this->render('UJMExoBundle:Exercise:paper.html.twig', $array); }
/** * Saves the score of a question that need manual correction. * * @EXT\Route("/papers/{id}/questions/{questionId}/score/{score}", name="exercise_save_score") * @EXT\Method("PUT") * @EXT\ParamConverter("question", class="UJMExoBundle:Question", options={"mapping": {"questionId": "id"}}) * * @param Question $question * @param Paper $paper * @param int $score * * @return JsonResponse */ public function saveScoreAction(Question $question, Paper $paper, $score) { $this->assertHasPermission('ADMINISTRATE', $paper->getExercise()); $this->paperManager->recordScore($question, $paper, $score); return new JsonResponse($this->paperManager->exportPaper($paper, $this->isAdmin($paper->getExercise())), 200); }
/** * To control if the user is allowed to display the paper * * @access private * * @param \Claroline\CoreBundle\Entity\User $user user connected * @param \UJM\ExoBundle\Entity\Paper $paper paper to display * * @return \Symfony\Component\HttpFoundation\Response */ private function ctrlDisplayPaper($user, $paper) { $display = 'none'; if ($this->container->get('ujm.exercise_services')->isExerciseAdmin($paper->getExercise()) || $user->getId() == $paper->getUser()->getId() && ($paper->getExercise()->getCorrectionMode() == 1 || $paper->getExercise()->getCorrectionMode() == 3 && $paper->getExercise()->getDateCorrection()->format('Y-m-d H:i:s') <= date("Y-m-d H:i:s") || $paper->getExercise()->getCorrectionMode() == 2 && $paper->getExercise()->getMaxAttempts() <= $this->container->get('ujm.exercise_services')->getNbPaper($user->getId(), $paper->getExercise()->getId()))) { $display = 'all'; } else { if ($user->getId() == $paper->getUser()->getId() && $paper->getExercise()->getMarkMode() == 2) { $display = 'score'; } } return $display; }
/** * For the navigation in a paper * Finds and displays the question selected by the User in an assessment. * * * @param int $numQuestionToDisplayed position of the question in the paper * @param \UJM\ExoBundle\Entity\Interaction $interactionToDisplay interaction (question) to displayed * @param string $typeInterToDisplayed * @param bool $dispButtonInterrupt to display or no the button "Interrupt" * @param int $maxAttempsAllowed the number of max attemps allowed for the exercise * @param Claroline workspace $workspace * @param \UJM\ExoBundle\Entity\Paper $paper current paper * @param SessionInterface session * * @return array */ public function displayQuestion($numQuestionToDisplayed, $interactionToDisplay, $typeInterToDisplayed, $dispButtonInterrupt, $maxAttempsAllowed, $workspace, Paper $paper, SessionInterface $session) { $tabOrderInter = $session->get('tabOrderInter'); $interSer = $this->container->get('ujm.exo_' . $interactionToDisplay->getType()); $interactionToDisplayed = $interSer->getInteractionX($interactionToDisplay->getId()); $responseGiven = $interSer->getResponseGiven($interactionToDisplay, $session, $interactionToDisplayed); $array['workspace'] = $workspace; $array['tabOrderInter'] = $tabOrderInter; $array['interactionToDisplayed'] = $interactionToDisplayed; $array['interactionType'] = $typeInterToDisplayed; $array['numQ'] = $numQuestionToDisplayed; $array['paper'] = $session->get('paper'); $array['numAttempt'] = $paper->getNumPaper(); $array['response'] = $responseGiven; $array['dispButtonInterrupt'] = $dispButtonInterrupt; $array['maxAttempsAllowed'] = $maxAttempsAllowed; $array['_resource'] = $paper->getExercise(); return $array; }