You are here

function _quiz_take_quiz_init in Quiz 8.4

Same name and namespace in other branches
  1. 7 quiz.module \_quiz_take_quiz_init()
  2. 7.4 quiz.module \_quiz_take_quiz_init()
1 call to _quiz_take_quiz_init()
quiz_take_quiz in ./quiz.module
Handles quiz taking.

File

./quiz.module, line 2280
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 array(
      'body' => array(
        '#value' => ' ',
      ),
    );
  }
  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/' . arg(1) . '/questions'),
    )), 'error');
    return array(
      'body' => array(
        '#value' => t('Please assign questions...'),
      ),
    );
  }

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