You are here

public function ClozeQuestion::evaluateAnswer in Cloze 6

Same name and namespace in other branches
  1. 7 cloze.classes.inc \ClozeQuestion::evaluateAnswer()

Evaluate the correctness of an answer based on the correct answer and evaluation method.

File

./cloze.classes.inc, line 200
The main classes for the short answer question type.

Class

ClozeQuestion
Extension of QuizQuestion.

Code

public function evaluateAnswer($user_answer) {
  $correct_answer = _cloze_get_correct_answer_chunks($this->node->body);
  $total_answer = count($correct_answer);
  $correct_answer_count = 0;
  if ($total_answer == 0) {
    return $this
      ->getMaximumScore();
  }
  foreach ($correct_answer as $key => $value) {
    if (drupal_strtolower($correct_answer[$key]) == drupal_strtolower($user_answer[$key])) {
      $correct_answer_count++;
    }
  }
  $score = $correct_answer_count / $total_answer * $this
    ->getMaximumScore();
  return round($score);
}