/**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * Check if the solution of the Paper is available to User.
  *
  * @param Exercise $exercise
  * @param Paper    $paper
  *
  * @return bool
  */
 public function isSolutionAvailable(Exercise $exercise, Paper $paper)
 {
     $correctionMode = $exercise->getCorrectionMode();
     switch ($correctionMode) {
         case CorrectionMode::AFTER_END:
             $available = !empty($paper->getEnd());
             break;
         case CorrectionMode::AFTER_LAST_ATTEMPT:
             $available = 0 === $exercise->getMaxAttempts() || $paper->getNumPaper() === $exercise->getMaxAttempts();
             break;
         case CorrectionMode::AFTER_DATE:
             $now = new \DateTime();
             $available = empty($exercise->getDateCorrection()) || $now >= $exercise->getDateCorrection();
             break;
         case CorrectionMode::NEVER:
         default:
             $available = false;
             break;
     }
     return $available;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }