Пример #1
0
}
if (!($course = $DB->get_record('course', array('id' => $cm->course)))) {
    print_error("coursemisconf");
}
if (!($quiz = $DB->get_record('quiz', array('id' => $cm->instance)))) {
    print_error('invalidcoursemodule');
}
$quizobj = new quiz($quiz, $cm, $course);
/// Check login and sesskey.
require_login($quizobj->get_courseid(), false, $quizobj->get_cm());
if (!confirm_sesskey()) {
    throw new moodle_exception('confirmsesskeybad', 'error', $quizobj->view_url());
}
/// if no questions have been set up yet redirect to edit.php
if (!$quizobj->get_question_ids() && $quizobj->has_capability('mod/quiz:manage')) {
    redirect($quizobj->edit_url());
}
/// Create an object to manage all the other (non-roles) access rules.
$accessmanager = $quizobj->get_access_manager(time());
if ($quizobj->is_preview_user() && $forcenew) {
    $accessmanager->clear_password_access();
}
/// Check capabilites.
if (!$quizobj->is_preview_user()) {
    $quizobj->require_capability('mod/quiz:attempt');
}
/// Check to see if a new preview was requested.
if ($quizobj->is_preview_user() && $forcenew) {
    /// To force the creation of a new preview, we set a finish time on the
    /// current attempt (if any). It will then automatically be deleted below
    $DB->set_field('quiz_attempts', 'timefinish', time(), array('quiz' => $quiz->id, 'userid' => $USER->id));