Esempio n. 1
0
/**
* 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;
}
Esempio n. 2
0
 /**
  * Load basic information about the state of each question.
  *
  * This is enough to, for example, show the state of each question in the
  * navigation panel, but only takes one DB query.
  */
 public function preload_question_states()
 {
     if (empty($this->questionids)) {
         throw new moodle_quiz_exception($this, 'noquestions', $this->edit_url());
     }
     $this->states = question_preload_states($this->attempt->uniqueid);
     if (!$this->states) {
         $this->states = array();
     }
 }