function quiz_end_scoring in Quiz 7.6
Same name and namespace in other branches
- 8.4 quiz.module \quiz_end_scoring()
- 6.4 quiz.module \quiz_end_scoring()
- 7 quiz.module \quiz_end_scoring()
- 7.4 quiz.module \quiz_end_scoring()
- 7.5 quiz.module \quiz_end_scoring()
Score a completed quiz.
Related topics
1 call to quiz_end_scoring()
- quiz_question_answering_form_finalize in question_types/
quiz_question/ quiz_question.module - Helper function to finalize a quiz attempt.
File
- ./
quiz.module, line 1967 - quiz.module Main file for the Quiz module.
Code
function quiz_end_scoring($result_id) {
global $user;
$quiz_result = quiz_result_load($result_id);
$quiz = node_load($quiz_result->nid, $quiz_result->vid);
$questions = $quiz_result->layout;
// Mark all missing answers as blank. This is essential here for when we may
// have pages of unanswered questions. Also kills a lot of the skip code that
// was necessary before.
foreach ($quiz_result->layout as $qinfo) {
// Load the Quiz answer submission from the database.
$qra = quiz_result_answer_load($result_id, $qinfo['nid'], $qinfo['vid']);
$current_question = node_load($qinfo['nid'], $qinfo['vid']);
foreach ($questions as $question) {
if ($question['nid'] == $current_question->nid) {
$question_array = $question;
}
}
if (!$qra) {
// This is the same skip code as in quiz_question_answering_form_submit() @todo find a way to save code.
$qi_instance = _quiz_question_response_get_instance($result_id, $current_question, NULL);
$qi_instance
->delete();
$bare_object = $qi_instance
->toBareObject();
quiz_store_question_result($quiz, $bare_object, array(
'set_msg' => TRUE,
'question_data' => $question_array,
));
}
}
$score = quiz_calculate_score($quiz, $result_id);
if (!isset($score['percentage_score'])) {
$score['percentage_score'] = 0;
}
$quiz_result->is_evaluated = $score['is_evaluated'];
$quiz_result->score = $score['percentage_score'];
$quiz_result->time_end = REQUEST_TIME;
entity_save('quiz_result', $quiz_result);
if ($user->uid) {
$score['passing'] = quiz_is_passed($user->uid, $quiz->nid, $quiz->vid);
}
else {
$score['passing'] = $score['percentage_score'] >= $quiz->pass_rate;
}
return $score;
}