You are here

function quiz_question_answering_form_finalize in Quiz 7.6

Same name and namespace in other branches
  1. 7.5 question_types/quiz_question/quiz_question.module \quiz_question_answering_form_finalize()

Helper function to finalize a quiz attempt.

See also

quiz_question_answering_form_submit()

quiz_question_answering_form_submit_blank()

2 calls to quiz_question_answering_form_finalize()
quiz_question_answering_form_submit in question_types/quiz_question/quiz_question.module
Submit handler for the question answering form.
quiz_question_answering_form_submit_blank in question_types/quiz_question/quiz_question.module
Submit action for "leave blank".

File

question_types/quiz_question/quiz_question.module, line 890
Quiz Question module. This module provides the basic facilities for adding quiz question types to a quiz.

Code

function quiz_question_answering_form_finalize(&$form, &$form_state) {
  $quiz_result = quiz_result_load($_SESSION['quiz'][arg(1)]['result_id']);
  $quiz = node_load($quiz_result->nid, $quiz_result->vid);

  // No more questions. Score quiz.
  $score = quiz_end_scoring($_SESSION['quiz'][$quiz->nid]['result_id']);
  if (empty($quiz->review_options['question']) || !array_filter($quiz->review_options['question']) || empty($form_state['feedback'])) {

    // Only redirect to question results if there is not question feedback.
    $form_state['redirect'] = "node/{$quiz->nid}/quiz-results/{$quiz_result->result_id}/view";
  }
  quiz_end_actions($quiz, $score, $_SESSION['quiz'][$quiz->nid]);

  // Remove all information about this quiz from the session.
  // @todo but for anon, we might have to keep some so they could access
  // results
  // When quiz is completed we need to make sure that even though the quiz has
  // been removed from the session, that the user can still access the
  // feedback for the last question, THEN go to the results page.
  $_SESSION['quiz']['temp']['result_id'] = $quiz_result->result_id;
  unset($_SESSION['quiz'][$quiz->nid]);
}