本文整理汇总了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();
}