public function ShortAnswerQuestion::evaluateAnswer in Quiz 8.4
Evaluate the correctness of an answer based on the correct answer and evaluation method.
File
- question_types/
short_answer/ lib/ Drupal/ short_answer/ ShortAnswerQuestion.php, line 238 - The main classes for the short answer question type.
Class
- ShortAnswerQuestion
- Extension of QuizQuestion.
Namespace
Drupal\short_answerCode
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->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;
}