本文整理匯總了PHP中quiz::__construct方法的典型用法代碼示例。如果您正苦於以下問題:PHP quiz::__construct方法的具體用法?PHP quiz::__construct怎麽用?PHP quiz::__construct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類quiz
的用法示例。
在下文中一共展示了quiz::__construct方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1:
/**
* 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();
}
示例2:
/**
* 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();
}