function quiz_update_total_score in Quiz 7.6
Same name and namespace in other branches
- 8.4 quiz.module \quiz_update_total_score()
- 6.6 quiz.module \quiz_update_total_score()
- 6.3 quiz.module \quiz_update_total_score()
- 6.4 quiz.module \quiz_update_total_score()
- 6.5 quiz.module \quiz_update_total_score()
- 7 quiz.module \quiz_update_total_score()
- 7.4 quiz.module \quiz_update_total_score()
- 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.
$result_id: The result ID to update.
Return value
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 2200 - quiz.module Main file for the Quiz module.
Code
function quiz_update_total_score($quiz, $result_id) {
$score = quiz_calculate_score($quiz, $result_id);
db_update('quiz_node_results')
->fields(array(
'score' => $score['percentage_score'],
))
->condition('result_id', $result_id)
->execute();
if ($score['is_evaluated']) {
// Call hook_quiz_scored().
module_invoke_all('quiz_scored', $quiz, $score, $result_id);
_quiz_maintain_results($quiz, $result_id);
db_update('quiz_node_results')
->fields(array(
'is_evaluated' => 1,
))
->condition('result_id', $result_id)
->execute();
}
return $score['percentage_score'];
}