You are here

function _quiz_take_quiz_init in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.module \_quiz_take_quiz_init()
  2. 7.4 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 2077
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->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]['question_duration'] = $quiz->time_limit;
  $_SESSION['quiz_' . $quiz->nid]['quiz_vid'] = $quiz->vid;
}