You are here

function restore_question_state in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/lib/questionlib.php \restore_question_state()

Creates the run-time fields for the states

Extends the state objects for a question by calling {@link restore_session_and_responses()}


object $question The question for which the state is needed:

object $state The state as loaded from the database:

Return value

boolean Represents success or failure

2 calls to restore_question_state()
get_question_states in includes/moodle/lib/questionlib.php
Loads the most recent state of each question session from the database or create new one.
regrade_question_in_attempt in includes/moodle/lib/questionlib.php
For a given question in an attempt we walk the complete history of states and recalculate the grades as we go along.


includes/moodle/lib/questionlib.php, line 935


function restore_question_state(&$question, &$state) {
  global $QTYPES;

  // initialise response to the value in the answer field
  $state->responses = array(
    '' => addslashes($state->answer),
  $state->manualcomment = isset($state->manualcomment) ? addslashes($state->manualcomment) : '';

  // Set the changed field to false; any code which changes the
  // question session must set this to true and must increment
  // ->seq_number. The save_question_session
  // function will save the new state object to the database if the field is
  // set to true.
  $state->changed = false;

  // Load the question type specific data
  return $QTYPES[$question->qtype]
    ->restore_session_and_responses($question, $state);