You are here

public function ShortAnswerQuestion::evaluateAnswer in Quiz 6.3

Same name and namespace in other branches
  1. 6.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
  2. 6.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
  3. 6.5 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
  4. 7.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
  5. 7 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
  6. 7.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerQuestion::evaluateAnswer()
  7. 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 197
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;
}