/** * @see ExerciseControllerInterface::registerAnswerAction(); * * @param \_OurBrand_\Quiz\Domain\Model\Exercises\MatchSequenceExercise $exercise * @return void */ public function registerAnswerAction($exercise) { $answers = $this->request->hasArgument('answeredPhrases') ? $this->request->getArgument('answeredPhrases') : array(); $score = $exercise->calculateScoreForAnswers($answers); $status = $exercise->isCompleted($answers); $orderedAnswers = $this->request->hasArgument('basePhrases') ? $this->request->getArgument('basePhrases') : array(); $identifier = $this->persistenceManager->getIdentifierByObject($exercise); $this->loginSession->setData('answers-' . $identifier, array_unique($orderedAnswers)); // Save the score, for the given answers, on this exercise, during this quiz. $this->exerciseService->registerAnswer($score, $status, $answers, $exercise, $this->studentQuizSession); $this->studentQuizSessionService->updateProgress($this->studentQuizSession); $this->view->assign('value', array('timeRemaining' => $this->studentQuizSession->getTimeRemaining())); if (!$this->isJson) { $this->redirect('studentnavigate', 'quiz', $this->request->hasArgument('goto') ? $this->request->getArgument('goto') : 'next'); } }
/** * @dataProvider calculateScore2DataProvider * @param array $data * @param integer $expected */ public function testCalculateScore2($data, $expected) { $exercise = new MatchSequenceExercise(); $arr = array('a', '', 'c', 'd', 'e', 'f'); $exercise->setPhrasesFromArray($arr); $this->assertSame($expected, $exercise->calculateScoreForAnswers($data)); }