2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * This page prints a review of a particular quiz attempt
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.
24 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 use mod_quiz\output\attempt_summary_information
;
29 use mod_quiz\output\navigation_panel_review
;
30 use mod_quiz\output\renderer
;
31 use mod_quiz\quiz_attempt
;
33 require_once(__DIR__
. '/../../config.php');
34 require_once($CFG->dirroot
. '/mod/quiz/locallib.php');
35 require_once($CFG->dirroot
. '/mod/quiz/report/reportlib.php');
37 $attemptid = required_param('attempt', PARAM_INT
);
38 $page = optional_param('page', 0, PARAM_INT
);
39 $showall = optional_param('showall', null, PARAM_BOOL
);
40 $cmid = optional_param('cmid', null, PARAM_INT
);
42 $url = new moodle_url('/mod/quiz/review.php', ['attempt' => $attemptid]);
44 $url->param('page', $page);
45 } else if ($showall) {
46 $url->param('showall', $showall);
49 $PAGE->set_secondary_active_tab("modulepage");
51 $attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
52 $attemptobj->preload_all_attempt_step_users();
53 $page = $attemptobj->force_page_number_into_range($page);
55 // Now we can validate the params better, re-genrate the page URL.
56 if ($showall === null) {
57 $showall = $page == 0 && $attemptobj->get_default_show_all('review');
59 $PAGE->set_url($attemptobj->review_url(null, $page, $showall));
62 require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
63 $attemptobj->check_review_capability();
65 // Create an object to manage all the other (non-roles) access rules.
66 $accessmanager = $attemptobj->get_access_manager(time());
67 $accessmanager->setup_attempt_page($PAGE);
69 $options = $attemptobj->get_display_options(true);
71 // Check permissions - warning there is similar code in reviewquestion.php and
72 // quiz_attempt::check_file_access. If you change on, change them all.
73 if ($attemptobj->is_own_attempt()) {
74 if (!$attemptobj->is_finished()) {
75 redirect($attemptobj->attempt_url(null, $page));
77 } else if (!$options->attempt
) {
78 $accessmanager->back_to_view_page($PAGE->get_renderer('mod_quiz'),
79 $attemptobj->cannot_review_message());
82 } else if (!$attemptobj->is_review_allowed()) {
83 throw new moodle_exception('noreviewattempt', 'quiz', $attemptobj->view_url());
86 // Load the questions and states needed by this page.
88 $questionids = $attemptobj->get_slots();
90 $questionids = $attemptobj->get_slots($page);
93 // Save the flag states, if they are being changed.
94 if ($options->flags
== question_display_options
::EDITABLE
&& optional_param('savingflags', false,
97 $attemptobj->save_question_flags();
98 redirect($attemptobj->review_url(null, $page, $showall));
101 // Work out appropriate title and whether blocks should be shown.
102 if ($attemptobj->is_own_preview()) {
103 navigation_node
::override_active_url($attemptobj->start_attempt_url());
106 if (empty($attemptobj->get_quiz()->showblocks
) && !$attemptobj->is_preview_user()) {
107 $PAGE->blocks
->show_only_fake_blocks();
111 // Set up the page header.
112 $headtags = $attemptobj->get_html_head_contributions($page, $showall);
113 $PAGE->set_title($attemptobj->review_page_title($page, $showall));
114 $PAGE->set_heading($attemptobj->get_course()->fullname
);
115 $PAGE->activityheader
->disable();
117 $summarydata = attempt_summary_information
::create_for_attempt($attemptobj, $options, $page, $showall);
120 $slots = $attemptobj->get_slots();
123 $slots = $attemptobj->get_slots($page);
124 $lastpage = $attemptobj->is_last_page($page);
127 /** @var renderer $output */
128 $output = $PAGE->get_renderer('mod_quiz');
130 // Arrange for the navigation to be displayed.
131 $navbc = $attemptobj->get_navigation_panel($output, navigation_panel_review
::class, $page, $showall);
132 $regions = $PAGE->blocks
->get_regions();
133 $PAGE->blocks
->add_fake_block($navbc, reset($regions));
135 echo $output->review_page($attemptobj, $slots, $page, $showall, $lastpage, $options, $summarydata);
137 // Trigger an event for this review.
138 $attemptobj->fire_attempt_reviewed_event();