You are here

function quiz_access_question in Quiz 7.5

Same name and namespace in other branches
  1. 7.6 quiz.module \quiz_access_question()

Menu check to see if user has access to take this question.

1 string reference to 'quiz_access_question'
quiz_menu in ./quiz.module
Implements hook_menu().

File

./quiz.module, line 3522
quiz.module Main file for the Quiz module.

Code

function quiz_access_question($quiz, $question_number) {
  if (!$question_number || empty($_SESSION['quiz'][$quiz->nid]['result_id'])) {
    return FALSE;
  }
  if ($quiz->allow_jumping) {

    // Access to go to any question. Yay.
    return TRUE;
  }
  $result_id = $_SESSION['quiz'][$quiz->nid]['result_id'];
  $quiz_result = quiz_result_load($result_id);
  $question_index = $question_number;
  $layout = $quiz_result
    ->getLayout();
  $qinfo_last = $question_number == 1 ? NULL : $layout[$question_index - 1];
  $qinfo = $layout[$question_index];
  $question_node = node_load($qinfo['nid'], $qinfo['vid']);
  $question_node_last = $qinfo_last ? node_load($qinfo_last['nid'], $qinfo_last['vid']) : NULL;
  if (!$quiz->backwards_navigation) {

    // No backwards navigation.
    if (quiz_result_is_question_answered($quiz_result, $question_node)) {

      // Already have an answer for the requested question.
      return FALSE;
    }
  }

  // Enforce normal navigation.
  if ($question_number == 1 || quiz_result_is_question_answered($quiz_result, $question_node_last)) {

    // Previous answer was submitted or this is the first question.
    return TRUE;
  }
}