/** * @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); }
/** * @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); }
/** * @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); }
/** * @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); }
/** * @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); }