示例#1
0
 /**
  * @todo handle global score option
  *
  * {@inheritdoc}
  */
 public function storeAnswerAndMark(Question $question, Response $response, $data)
 {
     $interaction = $this->om->getRepository('UJMExoBundle:InteractionHole')->findOneByQuestion($question);
     $answers = [];
     foreach ($data as $answer) {
         if ($answer && $answer !== null && !empty($answer['answerText'])) {
             $answers[] = $answer;
         }
     }
     $serviceHole = $this->container->get('ujm.exo.hole_service');
     $mark = $serviceHole->mark($interaction, $data, 0);
     if ($mark < 0) {
         $mark = 0;
     }
     $json = json_encode($answers);
     $response->setResponse($json);
     $response->setMark($mark);
 }
示例#2
0
 /**
  * @todo handle global score option
  *
  * {@inheritdoc}
  */
 public function storeAnswerAndMark(Question $question, Response $response, $data)
 {
     // a response is recorded like this : 471 - 335.9999694824219;583 - 125;
     $interaction = $this->om->getRepository('UJMExoBundle:InteractionGraphic')->findOneByQuestion($question);
     $coords = $interaction->getCoords();
     $score = 0;
     foreach ($coords as $coord) {
         $score += $coord->getScoreCoords();
     }
     if ($score === 0) {
         throw new \Exception('Global score not implemented yet');
     }
     $rightCoords = $this->om->getRepository('UJMExoBundle:Coords')->findBy(['interactionGraphic' => $interaction->getId()]);
     $answer = implode(';', array_map(function ($coords) {
         return (string) $coords['x'] . '-' . (string) $coords['y'];
     }, $data));
     // TODO : it would be easier to mark if we pass directly the decoded array of coords instead of the encode string
     $mark = $this->graphicService->mark($answer, $rightCoords, 0);
     if ($mark < 0) {
         $mark = 0;
     }
     $response->setResponse($answer);
     $response->setMark($mark);
 }
示例#3
0
 /**
  * @todo handle global score option
  *
  * {@inheritdoc}
  */
 public function storeAnswerAndMark(Question $question, Response $responseEntity, $data)
 {
     $interaction = $this->om->getRepository('UJMExoBundle:InteractionQCM')->findOneByQuestion($question);
     $serviceQCM = $this->container->get('ujm.exo.qcm_service');
     $allChoices = $interaction->getChoices();
     $mark = $serviceQCM->mark($interaction, $data, $allChoices, 0);
     if ($mark < 0) {
         $mark = 0;
     }
     $result = count($data) > 0 ? implode(';', $data) : '';
     $responseEntity->setResponse($result);
     $responseEntity->setMark($mark);
 }
示例#4
0
 private function applyPenalties(Paper $paper, Question $question, Response $response)
 {
     $penalty = $this->hintManager->getPenalty($paper, $question);
     $response->setMark($response->getMark() - $penalty);
     if ($response->getMark() < 0) {
         $response->setMark(0);
     }
 }
 /**
  * To navigate in the Questions of the assessment
  *
  * @access public
  *
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function exercisePaperNavAction(Request $request)
 {
     $response = '';
     $em = $this->getDoctrine()->getManager();
     $session = $request->getSession();
     $paper = $em->getRepository('UJMExoBundle:Paper')->find($session->get('paper'));
     $workspace = $paper->getExercise()->getResourceNode()->getWorkspace();
     $typeInterToRecorded = $request->get('typeInteraction');
     $tabOrderInter = $session->get('tabOrderInter');
     if ($paper->getEnd()) {
         return $this->forward('UJMExoBundle:Paper:show', array('id' => $paper->getId(), 'p' => -1));
     }
     //To record response
     $exerciseSer = $this->container->get('ujm.exercise_services');
     $ip = $exerciseSer->getIP();
     $interactionToValidatedID = $request->get('interactionToValidated');
     $response = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Response')->getAlreadyResponded($session->get('paper'), $interactionToValidatedID);
     switch ($typeInterToRecorded) {
         case "InteractionQCM":
             $res = $exerciseSer->responseQCM($request, $session->get('paper'));
             break;
         case "InteractionGraphic":
             $res = $exerciseSer->responseGraphic($request, $session->get('paper'));
             break;
         case "InteractionHole":
             $res = $exerciseSer->responseHole($request, $session->get('paper'));
             break;
         case "InteractionOpen":
             $res = $exerciseSer->responseOpen($request, $session->get('paper'));
             break;
         case "InteractionMatching":
             $res = $exerciseSer->responseMatching($request, $session->get('paper'));
             break;
     }
     if (count($response) == 0) {
         //INSERT Response
         $response = new Response();
         $response->setNbTries(1);
         $response->setPaper($paper);
         $response->setInteraction($em->getRepository('UJMExoBundle:Interaction')->find($interactionToValidatedID));
     } else {
         //UPDATE Response
         $response = $response[0];
         $response->setNbTries($response->getNbTries() + 1);
     }
     $response->setIp($ip);
     $score = explode('/', $res['score']);
     $response->setMark($score[0]);
     $response->setResponse($res['response']);
     $em->persist($response);
     $em->flush();
     //To display selectioned question
     $numQuestionToDisplayed = $request->get('numQuestionToDisplayed');
     if ($numQuestionToDisplayed == 'finish') {
         return $this->finishExercise($session);
     } else {
         if ($numQuestionToDisplayed == 'interupt') {
             return $this->interuptExercise();
         } else {
             $interactionToDisplayedID = $tabOrderInter[$numQuestionToDisplayed - 1];
             $interactionToDisplay = $em->getRepository('UJMExoBundle:Interaction')->find($interactionToDisplayedID);
             $typeInterToDisplayed = $interactionToDisplay->getType();
             return $this->displayQuestion($numQuestionToDisplayed, $interactionToDisplay, $typeInterToDisplayed, $response->getPaper()->getExercise()->getDispButtonInterrupt(), $response->getPaper()->getExercise()->getMaxAttempts(), $workspace, $paper);
         }
     }
 }
示例#6
0
 /**
  * @todo handle global score option
  *
  * {@inheritdoc}
  */
 public function storeAnswerAndMark(Question $question, Response $response, $data)
 {
     $interaction = $this->om->getRepository('UJMExoBundle:InteractionMatching')->findOneByQuestion($question);
     $labels = $interaction->getLabels();
     // at least one label must have a score
     $score = 0;
     $tabLabelGraduate = [];
     // store labels already considered in calculating the score
     foreach ($labels as $label) {
         // if first label
         if (count($tabLabelGraduate) === 0) {
             $score += $label->getScoreRightResponse();
         } elseif (count($tabLabelGraduate) > 0) {
             foreach ($tabLabelGraduate as $labelPast) {
                 // nothing in the array
                 if ($labelPast !== $label) {
                     $score += $label->getScoreRightResponse();
                 }
             }
         }
         // add the labels already considered
         array_push($tabLabelGraduate, $label);
     }
     if ($score === 0) {
         throw new \Exception('Global score not implemented yet');
     }
     $serviceMatching = $this->container->get('ujm.exo.matching_service');
     $tabsResponses = $serviceMatching->initTabResponseMatching($data, $interaction);
     $tabRightResponse = $tabsResponses[1];
     $tabResponseIndex = $tabsResponses[0];
     $mark = $serviceMatching->mark($interaction, 0, $tabRightResponse, $tabResponseIndex);
     if ($mark < 0) {
         $mark = 0;
     }
     $result = count($data) > 0 ? implode(';', $data) : '';
     $response->setResponse($result);
     $response->setMark($mark);
 }
示例#7
0
 /**
  * @todo handle global score option
  *
  * {@inheritdoc}
  */
 public function storeAnswerAndMark(Question $question, Response $response, $data)
 {
     $interaction = $this->om->getRepository('UJMExoBundle:InteractionOpen')->findOneByQuestion($question);
     $answer = $data;
     $serviceOpen = $this->container->get('ujm.exo.open_service');
     $mark = $serviceOpen->mark($interaction, $data, 0);
     $response->setResponse($answer);
     $response->setMark($mark);
 }