You are here

function _quiz_take_quiz_init in Quiz 7.4

Same name and namespace in other branches
  1. 8.4 quiz.module \_quiz_take_quiz_init()
  2. 7 quiz.module \_quiz_take_quiz_init()

Related topics

1 call to _quiz_take_quiz_init()
quiz_take_quiz in ./quiz.module
Handles quiz taking.

File

./quiz.module, line 2353
Quiz Module

Code

function _quiz_take_quiz_init($quiz) {

  // Create question list.
  $questions = quiz_build_question_list($quiz);
  if ($questions === FALSE) {
    drupal_set_message(t('Not enough random questions were found. Please add more questions before trying to take this @quiz.', array(
      '@quiz' => QUIZ_NAME,
    )), 'error');
    return FALSE;
  }
  if (count($questions) == 0) {
    drupal_set_message(t('No questions were found. Please !assign_questions before trying to take this @quiz.', array(
      '@quiz' => QUIZ_NAME,
      '!assign_questions' => l(t('assign questions'), 'node/' . $quiz->nid . '/questions'),
    )), 'error');
    return FALSE;
  }

  // Initialize session variables.
  $_SESSION['quiz_' . $quiz->nid]['result_id'] = quiz_create_rid($quiz);
  $_SESSION['quiz_' . $quiz->nid]['quiz_questions'] = $questions;
  $_SESSION['quiz_' . $quiz->nid]['previous_quiz_questions'] = array();
  $_SESSION['quiz_' . $quiz->nid]['question_number'] = 0;
  $_SESSION['quiz_' . $quiz->nid]['question_start_time'] = REQUEST_TIME;
  $_SESSION['quiz_' . $quiz->nid]['quiz_vid'] = $quiz->vid;
  if ($quiz->time_limit > 0) {
    $_SESSION['quiz_' . $quiz->nid]['question_duration'] = $quiz->time_limit;
  }
  return TRUE;
}