// question id
$stateid = optional_param('state', 0, PARAM_INT);
// state id
$attemptobj = new quiz_attempt($attemptid);
/// Check login.
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
$attemptobj->check_review_capability();
/// Permissions checks for normal users who do not have quiz:viewreports capability.
if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
    /// Can't review during the attempt - send them back to the attempt page.
    if (!$attemptobj->is_finished()) {
        notify(get_string('cannotreviewopen', 'quiz'));
        close_window_button();
    }
    /// Can't review other users' attempts.
    if (!$attemptobj->is_own_attempt()) {
        notify(get_string('notyourattempt', 'quiz'));
        close_window_button();
    }
    /// Can't review unless Students may review -> Responses option is turned on.
    if (!$options->responses) {
        $accessmanager = $attemptobj->get_access_manager(time());
        notify($accessmanager->cannot_review_message($attemptobj->get_review_options()));
        close_window_button();
    }
}
/// Load the questions and states.
$questionids = array($questionid);
$attemptobj->load_questions($questionids);
$attemptobj->load_question_states($questionids);
/// If it was asked for, load another state, instead of the latest.
Example #2
0
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
require_once $CFG->dirroot . '/mod/quiz/report/reportlib.php';
$attemptid = required_param('attempt', PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$showall = optional_param('showall', 0, PARAM_BOOL);
$attemptobj = new quiz_attempt($attemptid);
/// Check login.
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
$attemptobj->check_review_capability();
/// Create an object to manage all the other (non-roles) access rules.
$accessmanager = $attemptobj->get_access_manager(time());
$options = $attemptobj->get_review_options();
/// Permissions checks for normal users who do not have quiz:viewreports capability.
if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
    /// Can't review other users' attempts.
    if (!$attemptobj->is_own_attempt()) {
        quiz_error($attemptobj->get_quiz(), 'notyourattempt');
    }
    /// Can't review during the attempt - send them back to the attempt page.
    if (!$attemptobj->is_finished()) {
        redirect($attemptobj->attempt_url(0, $page));
    }
    /// Can't review unless Students may review -> Responses option is turned on.
    if (!$options->responses) {
        $accessmanager->back_to_view_page($attemptobj->is_preview_user(), $accessmanager->cannot_review_message($options));
    }
}
/// Load the questions and states needed by this page.
if ($showall) {
    $questionids = $attemptobj->get_question_ids();
} else {