public function ShortAnswerQuestion::evaluateAnswer in Quiz 7.5
Same name and namespace in other branches
- 6.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
- 6.3 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
- 6.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
- 6.5 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
- 7.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
- 7 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
- 7.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
Evaluate the correctness of an answer.
The way we decide how to evaluate the correctness depends on the evaluation method of the question.
Parameters
string $user_answer: The answer given by the user.
Return value
int The given score for the answer.
File
- question_types/
short_answer/ short_answer.classes.inc, line 236 - Short answer classes.
Class
- ShortAnswerQuestion
- Extension of QuizQuestion.
Code
public function evaluateAnswer($user_answer) {
$score = 0;
// Ignore white spaces for correct answer and user's answer.
$user_answer = trim($user_answer);
$this->node->correct_answer = trim($this->node->correct_answer);
switch ($this->node->correct_answer_evaluation) {
case self::ANSWER_MATCH:
if ($user_answer == $this->node->correct_answer) {
$score = $this->node->max_score;
}
break;
case self::ANSWER_INSENSITIVE_MATCH:
if (drupal_strtolower($user_answer) == drupal_strtolower($this->node->correct_answer)) {
$score = $this->node->max_score;
}
break;
case self::ANSWER_REGEX:
if (preg_match($this->node->correct_answer, $user_answer) > 0) {
$score = $this->node->max_score;
}
break;
}
return $score;
}