/** * Loads the most recent state of each question session from the database * or create new one. * * For each question the most recent session state for the current attempt * is loaded from the question_states table and the question type specific data and * responses are added by calling {@link restore_question_state()} which in turn * calls {@link restore_session_and_responses()} for each question. * If no states exist for the question instance an empty state object is * created representing the start of a session and empty question * type specific information and responses are created by calling * {@link create_session_and_responses()}. * * @return array An array of state objects representing the most recent * states of the question sessions. * @param array $questions The questions for which sessions are to be restored or * created. * @param object $cmoptions * @param object $attempt The attempt for which the question sessions are * to be restored or created. * @param mixed either the id of a previous attempt, if this attmpt is * building on a previous one, or false for a clean attempt. */ function get_question_states(&$questions, $cmoptions, $attempt, $lastattemptid = false) { // Preload the states. $states = question_preload_states($attempt->uniqueid); if (!$states) { $states = array(); } // Then finish the job. if (!question_load_states($questions, $states, $cmoptions, $attempt, $lastattemptid)) { return false; } return $states; }
/** * Load the state of a number of questions that have already been loaded. * * @param array $questionids question ids to process. Blank = all. */ public function load_question_states($questionids = null) { if (is_null($questionids)) { $questionids = $this->questionids; } $questionstoprocess = array(); foreach ($questionids as $id) { $this->ensure_question_loaded($id); $questionstoprocess[$id] = $this->questions[$id]; } if (!question_load_states($questionstoprocess, $this->states, $this->quiz, $this->attempt)) { throw new moodle_quiz_exception($this, 'cannotrestore'); } }