You are here

function quiz_update_total_score in Quiz 7.5

Same name and namespace in other branches
  1. 8.4 quiz.module \quiz_update_total_score()
  2. 6.6 quiz.module \quiz_update_total_score()
  3. 6.3 quiz.module \quiz_update_total_score()
  4. 6.4 quiz.module \quiz_update_total_score()
  5. 6.5 quiz.module \quiz_update_total_score()
  6. 7.6 quiz.module \quiz_update_total_score()
  7. 7 quiz.module \quiz_update_total_score()
  8. 7.4 quiz.module \quiz_update_total_score()

Update a score for a quiz.

This updates the quiz node results table.

It is used in cases where a quiz score is changed after the quiz has been taken. For example, if a long answer question is scored later by a human, then the quiz should be updated when that answer is scored.

Important: The value stored in the table is the *percentage* score.

Parameters

$quiz: The quiz node for the quiz that is being scored.

$result_id: The result ID to update.

Return value

int The score as an integer representing percentage. E.g. 55 is 55%.

Related topics

2 calls to quiz_update_total_score()
long_answer_score_an_answer in question_types/long_answer/long_answer.module
Set a score for a long answer question.
short_answer_score_an_answer in question_types/short_answer/short_answer.module
Set a score for a short answer question.

File

./quiz.module, line 2084
quiz.module Main file for the Quiz module.

Code

function quiz_update_total_score($quiz, $result_id) {
  $score = quiz_calculate_score($result_id);
  $result = quiz_result_load($result_id);
  $result->score = $score['percentage_score'];
  $result
    ->save();
  if ($score['is_evaluated']) {

    // Call hook_quiz_scored().
    module_invoke_all('quiz_scored', $quiz, $score, $result_id);
    _quiz_maintain_results($quiz, $result_id);
    $result->is_evaluated = 1;
    $result
      ->save();
  }
  return $score['percentage_score'];
}