public function MatchingResponse::score in Quiz 6.6
Same name and namespace in other branches
- 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.6 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()
File
- question_types/
matching/ matching.classes.inc, line 245 - matching.classes
Class
- MatchingResponse
- Class that describes a "Directions question response". For the most part, no real scoring takes place for a direction node. However, there are a few behind-the-scenes tricks that are done here to make the quiz-taking process a little easier.
Code
public function score() {
$wrong_answer = 0;
$correct_answer = 0;
$user_answers = isset($this->answer) ? $this->answer : $this
->getUserAnswers();
$user_answers = isset($user_answers) ? $user_answers : array();
// to prevent warning : Invalid argument supplied for foreach()
foreach ((array) $user_answers as $key => $value) {
if ($key != $value) {
$wrong_answer++;
}
else {
$correct_answer++;
}
}
$score = $correct_answer - $wrong_answer;
return $score < 0 ? 0 : $score;
}