/** * Constructor assuming we already have the necessary data loaded. * * @param object $attempt the row of the quiz_attempts table. * @param object $quiz the quiz object for this attempt and user. * @param object $cm the course_module object for this quiz. * @param object $course the row from the course table for the course we belong to. */ function __construct($attempt, $quiz, $cm, $course) { $this->attempt = $attempt; parent::__construct($quiz, $cm, $course); $this->preload_questions(); $this->preload_question_states(); }
/** * Constructor from just an attemptid. * * @param integer $attemptid the id of the attempt to load. We automatically load the * associated quiz, course, etc. */ function __construct($attemptid) { global $DB; if (!($this->attempt = quiz_load_attempt($attemptid))) { throw new moodle_exception('invalidattemptid', 'quiz'); } if (!($quiz = $DB->get_record('quiz', array('id' => $this->attempt->quiz)))) { throw new moodle_exception('invalidquizid', 'quiz'); } if (!($course = $DB->get_record('course', array('id' => $quiz->course)))) { throw new moodle_exception('invalidcoursemodule'); } if (!($cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id))) { throw new moodle_exception('invalidcoursemodule'); } parent::__construct($quiz, $cm, $course); $this->preload_questions(); $this->preload_question_states(); }