You are here

function quiz_update_total_score in Quiz 8.4

Same name and namespace in other branches
  1. 6.6 quiz.module \quiz_update_total_score()
  2. 6.3 quiz.module \quiz_update_total_score()
  3. 6.4 quiz.module \quiz_update_total_score()
  4. 6.5 quiz.module \quiz_update_total_score()
  5. 7.6 quiz.module \quiz_update_total_score()
  6. 7 quiz.module \quiz_update_total_score()
  7. 7.4 quiz.module \quiz_update_total_score()
  8. 7.5 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.

$rid: The result ID to update.

Return value

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

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 3266
Quiz Module

Code

function quiz_update_total_score($quiz, $rid) {
  $score = quiz_calculate_score($quiz, $rid);
  db_update('quiz_node_results')
    ->fields(array(
    'score' => $score['percentage_score'],
  ))
    ->condition('result_id', $rid)
    ->execute();
  if ($score['is_evaluated']) {

    // Call hook_quiz_scored().
    module_invoke_all('quiz_scored', $quiz, $score, $rid);
    _quiz_maintain_results($quiz, $rid);
    db_update('quiz_node_results')
      ->fields(array(
      'is_evaluated' => 1,
    ))
      ->condition('result_id', $rid)
      ->execute();
  }
  return $score['percentage_score'];
}