public function ShortAnswerQuestion::evaluateAnswer in Quiz 6.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()
- 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()
- 7.5 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
Evaluate the correctness of an answer based on the correct answer and evaluation method.
File
- question_types/
short_answer/ short_answer.classes.inc, line 196 - The main classes for the short answer question type.
Class
- ShortAnswerQuestion
- Implementation of QuizQuestion.
Code
public function evaluateAnswer($user_answer) {
$score = 0;
switch ($this->node->correct_answer_evaluation) {
case self::ANSWER_MATCH:
if ($user_answer == $this->node->correct_answer) {
$score = $this->node->maximum_score;
}
break;
case self::ANSWER_INSENSITIVE_MATCH:
if (drupal_strtolower($user_answer) == drupal_strtolower($this->node->correct_answer)) {
$score = $this->node->maximum_score;
}
break;
case self::ANSWER_REGEX:
//drupal_set_message('Regex is: ' . $this->node->correct_answer, 'status');
if (preg_match($this->node->correct_answer, $user_answer) > 0) {
$score = $this->node->maximum_score;
}
break;
}
return $score;
}