public function MatchingResponse::score in Quiz 7.6
Same name and namespace in other branches
- 6.6 question_types/matching/matching.classes.inc \MatchingResponse::score()
- 6.3 question_types/matching/matching.classes.inc \MatchingResponse::score()
- 6.4 question_types/matching/matching.classes.inc \MatchingResponse::score()
- 6.5 question_types/matching/matching.classes.inc \MatchingResponse::score()
- 7 question_types/matching/matching.classes.inc \MatchingResponse::score()
- 7.4 question_types/matching/matching.classes.inc \MatchingResponse::score()
- 7.5 question_types/matching/matching.classes.inc \MatchingResponse::score()
Implementation of score
Overrides QuizQuestionResponse::score
See also
QuizQuestionResponse#score()
File
- question_types/
matching/ matching.classes.inc, line 489 - matching.classes
Class
- MatchingResponse
- Extension of QuizQuestionResponse
Code
public function score() {
$wrong_answer = 0;
$correct_answer = 0;
$user_answers = isset($this->answer['answer']) ? $this->answer['answer'] : $this->answer;
$MatchingQuestion = new MatchingQuestion($this->question);
$correct_answers = $MatchingQuestion
->getCorrectAnswer();
foreach ((array) $user_answers as $key => $value) {
if ($value != 0 && $correct_answers[$key]['answer'] == $correct_answers[$value]['answer']) {
$correct_answer++;
}
elseif ($value == 0 || $value == 'def') {
}
else {
$wrong_answer++;
}
}
$score = $correct_answer;
if ($this->question->choice_penalty) {
$score -= $wrong_answer;
}
return $score < 0 ? 0 : $score;
}