Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This page prints a review of a particular quiz attempt 19 * 20 * It is used either by the student whose attempts this is, after the attempt, 21 * or by a teacher reviewing another's attempt during or afterwards. 22 * 23 * @package mod_quiz 24 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 */ 27 28 use mod_quiz\output\navigation_panel_review; 29 use mod_quiz\output\renderer; 30 use mod_quiz\quiz_attempt; 31 32 require_once(__DIR__ . '/../../config.php'); 33 require_once($CFG->dirroot . '/mod/quiz/locallib.php'); 34 require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); 35 36 $attemptid = required_param('attempt', PARAM_INT); 37 $page = optional_param('page', 0, PARAM_INT); 38 $showall = optional_param('showall', null, PARAM_BOOL); 39 $cmid = optional_param('cmid', null, PARAM_INT); 40 41 $url = new moodle_url('/mod/quiz/review.php', ['attempt' => $attemptid]); 42 if ($page !== 0) { 43 $url->param('page', $page); 44 } else if ($showall) { 45 $url->param('showall', $showall); 46 } 47 $PAGE->set_url($url); 48 $PAGE->set_secondary_active_tab("modulepage"); 49 50 $attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid); 51 $attemptobj->preload_all_attempt_step_users(); 52 $page = $attemptobj->force_page_number_into_range($page); 53 54 // Now we can validate the params better, re-genrate the page URL. 55 if ($showall === null) { 56 $showall = $page == 0 && $attemptobj->get_default_show_all('review'); 57 } 58 $PAGE->set_url($attemptobj->review_url(null, $page, $showall)); 59 60 // Check login. 61 require_login($attemptobj->get_course(), false, $attemptobj->get_cm()); 62 $attemptobj->check_review_capability(); 63 64 // Create an object to manage all the other (non-roles) access rules. 65 $accessmanager = $attemptobj->get_access_manager(time()); 66 $accessmanager->setup_attempt_page($PAGE); 67 68 $options = $attemptobj->get_display_options(true); 69 70 // Check permissions - warning there is similar code in reviewquestion.php and 71 // quiz_attempt::check_file_access. If you change on, change them all. 72 if ($attemptobj->is_own_attempt()) { 73 if (!$attemptobj->is_finished()) { 74 redirect($attemptobj->attempt_url(null, $page)); 75 76 } else if (!$options->attempt) { 77 $accessmanager->back_to_view_page($PAGE->get_renderer('mod_quiz'), 78 $attemptobj->cannot_review_message()); 79 } 80 81 } else if (!$attemptobj->is_review_allowed()) { 82 throw new moodle_exception('noreviewattempt', 'quiz', $attemptobj->view_url()); 83 } 84 85 // Load the questions and states needed by this page. 86 if ($showall) { 87 $questionids = $attemptobj->get_slots(); 88 } else { 89 $questionids = $attemptobj->get_slots($page); 90 } 91 92 // Save the flag states, if they are being changed. 93 if ($options->flags == question_display_options::EDITABLE && optional_param('savingflags', false, 94 PARAM_BOOL)) { 95 require_sesskey(); 96 $attemptobj->save_question_flags(); 97 redirect($attemptobj->review_url(null, $page, $showall)); 98 } 99 100 // Work out appropriate title and whether blocks should be shown. 101 if ($attemptobj->is_own_preview()) { 102 navigation_node::override_active_url($attemptobj->start_attempt_url()); 103 104 } else { 105 if (empty($attemptobj->get_quiz()->showblocks) && !$attemptobj->is_preview_user()) { 106 $PAGE->blocks->show_only_fake_blocks(); 107 } 108 } 109 110 // Set up the page header. 111 $headtags = $attemptobj->get_html_head_contributions($page, $showall); 112 $PAGE->set_title($attemptobj->review_page_title($page, $showall)); 113 $PAGE->set_heading($attemptobj->get_course()->fullname); 114 $PAGE->activityheader->disable(); 115 116 // Summary table start. ============================================================================ 117 118 // Work out some time-related things. 119 $attempt = $attemptobj->get_attempt(); 120 $quiz = $attemptobj->get_quiz(); 121 $overtime = 0; 122 123 if ($attempt->state == quiz_attempt::FINISHED) { 124 if ($timetaken = ($attempt->timefinish - $attempt->timestart)) { 125 if ($quiz->timelimit && $timetaken > ($quiz->timelimit + 60)) { 126 $overtime = $timetaken - $quiz->timelimit; 127 $overtime = format_time($overtime); 128 } 129 $timetaken = format_time($timetaken); 130 } else { 131 $timetaken = "-"; 132 } 133 } else { 134 $timetaken = get_string('unfinished', 'quiz'); 135 } 136 137 // Prepare summary informat about the whole attempt. 138 $summarydata = []; 139 if (!$attemptobj->get_quiz()->showuserpicture && $attemptobj->get_userid() != $USER->id) { 140 // If showuserpicture is true, the picture is shown elsewhere, so don't repeat it. 141 $student = $DB->get_record('user', ['id' => $attemptobj->get_userid()]); 142 $userpicture = new user_picture($student); 143 $userpicture->courseid = $attemptobj->get_courseid(); 144 $summarydata['user'] = [ 145 'title' => $userpicture, 146 'content' => new action_link(new moodle_url('/user/view.php', [ 147 'id' => $student->id, 'course' => $attemptobj->get_courseid()]), 148 fullname($student, true)), 149 ]; 150 } 151 152 if ($attemptobj->has_capability('mod/quiz:viewreports')) { 153 $attemptlist = $attemptobj->links_to_other_attempts($attemptobj->review_url(null, $page, 154 $showall)); 155 if ($attemptlist) { 156 $summarydata['attemptlist'] = [ 157 'title' => get_string('attempts', 'quiz'), 158 'content' => $attemptlist, 159 ]; 160 } 161 } 162 163 // Timing information. 164 $summarydata['startedon'] = [ 165 'title' => get_string('startedon', 'quiz'), 166 'content' => userdate($attempt->timestart), 167 ]; 168 169 $summarydata['state'] = [ 170 'title' => get_string('attemptstate', 'quiz'), 171 'content' => quiz_attempt::state_name($attempt->state), 172 ]; 173 174 if ($attempt->state == quiz_attempt::FINISHED) { 175 $summarydata['completedon'] = [ 176 'title' => get_string('completedon', 'quiz'), 177 'content' => userdate($attempt->timefinish), 178 ]; 179 $summarydata['timetaken'] = [ 180 'title' => get_string('timetaken', 'quiz'), 181 'content' => $timetaken, 182 ]; 183 } 184 185 if (!empty($overtime)) { 186 $summarydata['overdue'] = [ 187 'title' => get_string('overdue', 'quiz'), 188 'content' => $overtime, 189 ]; 190 } 191 192 // Show marks (if the user is allowed to see marks at the moment). 193 $grade = quiz_rescale_grade($attempt->sumgrades, $quiz, false); 194 if ($options->marks >= question_display_options::MARK_AND_MAX && quiz_has_grades($quiz)) { 195 196 if ($attempt->state != quiz_attempt::FINISHED) { 197 // Cannot display grade. 198 199 } else if (is_null($grade)) { 200 $summarydata['grade'] = [ 201 'title' => get_string('grade', 'quiz'), 202 'content' => quiz_format_grade($quiz, $grade), 203 ]; 204 205 } else { 206 // Show raw marks only if they are different from the grade (like on the view page). 207 if ($quiz->grade != $quiz->sumgrades) { 208 $a = new stdClass(); 209 $a->grade = quiz_format_grade($quiz, $attempt->sumgrades); 210 $a->maxgrade = quiz_format_grade($quiz, $quiz->sumgrades); 211 $summarydata['marks'] = [ 212 'title' => get_string('marks', 'quiz'), 213 'content' => get_string('outofshort', 'quiz', $a), 214 ]; 215 } 216 217 // Now the scaled grade. 218 $a = new stdClass(); 219 $a->grade = html_writer::tag('b', quiz_format_grade($quiz, $grade)); 220 $a->maxgrade = quiz_format_grade($quiz, $quiz->grade); 221 if ($quiz->grade != 100) { 222 // Show the percentage using the configured number of decimal places, 223 // but without trailing zeroes. 224 $a->percent = html_writer::tag('b', format_float( 225 $attempt->sumgrades * 100 / $quiz->sumgrades, 226 $quiz->decimalpoints, true, true)); 227 $formattedgrade = get_string('outofpercent', 'quiz', $a); 228 } else { 229 $formattedgrade = get_string('outof', 'quiz', $a); 230 } 231 $summarydata['grade'] = [ 232 'title' => get_string('grade', 'quiz'), 233 'content' => $formattedgrade, 234 ]; 235 } 236 } 237 238 // Any additional summary data from the behaviour. 239 $summarydata = array_merge($summarydata, $attemptobj->get_additional_summary_data($options)); 240 241 // Feedback if there is any, and the user is allowed to see it now. 242 $feedback = $attemptobj->get_overall_feedback($grade); 243 if ($options->overallfeedback && $feedback) { 244 $summarydata['feedback'] = [ 245 'title' => get_string('feedback', 'quiz'), 246 'content' => $feedback, 247 ]; 248 } 249 250 // Summary table end. ============================================================================== 251 252 if ($showall) { 253 $slots = $attemptobj->get_slots(); 254 $lastpage = true; 255 } else { 256 $slots = $attemptobj->get_slots($page); 257 $lastpage = $attemptobj->is_last_page($page); 258 } 259 260 /** @var renderer $output */ 261 $output = $PAGE->get_renderer('mod_quiz'); 262 263 // Arrange for the navigation to be displayed. 264 $navbc = $attemptobj->get_navigation_panel($output, navigation_panel_review::class, $page, $showall); 265 $regions = $PAGE->blocks->get_regions(); 266 $PAGE->blocks->add_fake_block($navbc, reset($regions)); 267 268 echo $output->review_page($attemptobj, $slots, $page, $showall, $lastpage, $options, $summarydata); 269 270 // Trigger an event for this review. 271 $attemptobj->fire_attempt_reviewed_event();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body