Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b6f3e4f8f0
Fetching contributors…

Cannot retrieve contributors at this time

file 143 lines (121 sloc) 5.843 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
<?php
/**
* This page prints a review of a particular question attempt.
* This page is expected to only be used in a popup window.
*
* @author Martin Dougiamas, Tim Hunt and many others.
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package quiz
*/

    require_once(dirname(__FILE__) . '/../../config.php');
    require_once('locallib.php');

    $attemptid = required_param('attempt', PARAM_INT); // attempt id
    $questionid = required_param('question', PARAM_INT); // question id
    $stateid = optional_param('state', 0, PARAM_INT); // state id

    $url = new moodle_url('/mod/quiz/reviewquestion.php', array('attempt'=>$attemptid,'question'=>$questionid));
    if ($stateid !== 0) {
        $url->param('state', $stateid);
    }
    $PAGE->set_url($url);
    $PAGE->set_pagelayout('popup');

    $attemptobj = quiz_attempt::create($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 during the attempt - send them back to the attempt page.
        if (!$attemptobj->is_finished()) {
            echo $OUTPUT->header();
            echo $OUTPUT->notification(get_string('cannotreviewopen', 'quiz'));
            echo $OUTPUT->close_window_button();
            echo $OUTPUT->footer();
            die;
        }
    /// Can't review other users' attempts.
        if (!$attemptobj->is_own_attempt()) {
            echo $OUTPUT->header();
            echo $OUTPUT->notification(get_string('notyourattempt', 'quiz'));
            echo $OUTPUT->close_window_button();
            echo $OUTPUT->footer();
            die;
        }

    /// Can't review unless Students may review -> Responses option is turned on.
        if (!$options->responses) {
            $accessmanager = $attemptobj->get_access_manager(time());
            echo $OUTPUT->header();
            echo $OUTPUT->notification($accessmanager->cannot_review_message($attemptobj->get_review_options()));
            echo $OUTPUT->close_window_button();
            echo $OUTPUT->footer();
            die;
        }
    }

/// 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.
    if ($stateid) {
        $attemptobj->load_specific_question_state($questionid, $stateid);
    }

/// Work out the base URL of this page.
    $baseurl = $CFG->wwwroot . '/mod/quiz/reviewquestion.php?attempt=' .
            $attemptobj->get_attemptid() . '&amp;question=' . $questionid;

/// Log this review.
    add_to_log($attemptobj->get_courseid(), 'quiz', 'review', 'reviewquestion.php?attempt=' .
            $attemptobj->get_attemptid() . '&question=' . $questionid .
            ($stateid ? '&state=' . $stateid : ''),
            $attemptobj->get_quizid(), $attemptobj->get_cmid());

/// Print the page header
    $attemptobj->get_question_html_head_contributions($questionid);
    $PAGE->set_title($attemptobj->get_course()->shortname . ': '.format_string($attemptobj->get_quiz_name()));
    $PAGE->set_heading($COURSE->fullname);
    echo $OUTPUT->header();

/// Print infobox
    $rows = array();

/// User picture and name.
    if ($attemptobj->get_userid() <> $USER->id) {
        // Print user picture and name
        $student = $DB->get_record('user', array('id' => $attemptobj->get_userid()));
        $picture = $OUTPUT->user_picture($student, array('courseid'=>$attemptobj->get_courseid()));
        $rows[] = '<tr><th scope="row" class="cell">' . $picture . '</th><td class="cell"><a href="' .
                $CFG->wwwroot . '/user/view.php?id=' . $student->id . '&amp;course=' . $attemptobj->get_courseid() . '">' .
                fullname($student, true) . '</a></td></tr>';
    }

/// Quiz name.
    $rows[] = '<tr><th scope="row" class="cell">' . get_string('modulename', 'quiz') .
            '</th><td class="cell">' . format_string($attemptobj->get_quiz_name()) . '</td></tr>';

/// Question name.
    $rows[] = '<tr><th scope="row" class="cell">' . get_string('question', 'quiz') .
            '</th><td class="cell">' . format_string(
            $attemptobj->get_question($questionid)->name) . '</td></tr>';

/// Other attempts at the quiz.
    if ($attemptobj->has_capability('mod/quiz:viewreports')) {
        $attemptlist = $attemptobj->links_to_other_attempts($baseurl);
        if ($attemptlist) {
            $rows[] = '<tr><th scope="row" class="cell">' . get_string('attempts', 'quiz') .
                    '</th><td class="cell">' . $attemptlist . '</td></tr>';
        }
    }

/// Timestamp of this action.
    $timestamp = $attemptobj->get_question_state($questionid)->timestamp;
    if ($timestamp) {
        $rows[] = '<tr><th scope="row" class="cell">' . get_string('completedon', 'quiz') .
                '</th><td class="cell">' . userdate($timestamp) . '</td></tr>';
    }

/// Now output the summary table, if there are any rows to be shown.
    if (!empty($rows)) {
        echo '<table class="generaltable generalbox quizreviewsummary"><tbody>', "\n";
        echo implode("\n", $rows);
        echo "\n</tbody></table>\n";
    }

/// Print the question in the requested state.
    if ($stateid) {
        $baseurl .= '&amp;state=' . $stateid;
    }
    $attemptobj->print_question($questionid, true, $baseurl);

/// Finish the page
    echo $OUTPUT->footer();
Something went wrong with that request. Please try again.