You are here

function quiz_end_scoring in Quiz 7.5

Same name and namespace in other branches
  1. 8.4 quiz.module \quiz_end_scoring()
  2. 6.4 quiz.module \quiz_end_scoring()
  3. 7.6 quiz.module \quiz_end_scoring()
  4. 7 quiz.module \quiz_end_scoring()
  5. 7.4 quiz.module \quiz_end_scoring()

Score a completed quiz.

Related topics

2 calls to quiz_end_scoring()
quiz_question_answering_form_finalize in question_types/quiz_question/quiz_question.module
Helper function to finalize a quiz attempt.
quiz_report_form_submit in ./quiz.pages.inc
Submit the report form.

File

./quiz.module, line 2028
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
    ->getLayout();

  // 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 ($questions as $qinfo) {

    // Load the Quiz answer submission from the database.
    $qra = quiz_result_answer_load($result_id, $qinfo['nid'], $qinfo['vid']);

    // If the result answer has not been marked as skipped and it hasn't been
    // answered.
    if (empty($qra->is_skipped) && empty($qra->answer_timestamp)) {
      $qra->is_skipped = 1;
      entity_save('quiz_result_answer', $qra);
    }
  }
  $score = quiz_calculate_score($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;
}