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 summary of a quiz attempt before it is submitted.
21 * @copyright 2009 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once(__DIR__
. '/../../config.php');
27 require_once($CFG->dirroot
. '/mod/quiz/locallib.php');
29 $attemptid = required_param('attempt', PARAM_INT
); // The attempt to summarise.
30 $cmid = optional_param('cmid', null, PARAM_INT
);
32 $PAGE->set_url('/mod/quiz/summary.php', array('attempt' => $attemptid));
33 // During quiz attempts, the browser back/forwards buttons should force a reload.
34 $PAGE->set_cacheable(false);
35 $PAGE->set_secondary_active_tab("modulepage");
37 $attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
40 require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
42 // Check that this attempt belongs to this user.
43 if ($attemptobj->get_userid() != $USER->id
) {
44 if ($attemptobj->has_capability('mod/quiz:viewreports')) {
45 redirect($attemptobj->review_url(null));
47 throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt');
52 if (!$attemptobj->is_preview_user()) {
53 $attemptobj->require_capability('mod/quiz:attempt');
56 if ($attemptobj->is_preview_user()) {
57 navigation_node
::override_active_url($attemptobj->start_attempt_url());
61 $accessmanager = $attemptobj->get_access_manager(time());
62 $accessmanager->setup_attempt_page($PAGE);
63 $output = $PAGE->get_renderer('mod_quiz');
64 $messages = $accessmanager->prevent_access();
65 if (!$attemptobj->is_preview_user() && $messages) {
66 throw new \
moodle_exception('attempterror', 'quiz', $attemptobj->view_url(),
67 $output->access_messages($messages));
69 if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) {
70 redirect($attemptobj->start_attempt_url(null));
73 $displayoptions = $attemptobj->get_display_options(false);
75 // If the attempt is now overdue, or abandoned, deal with that.
76 $attemptobj->handle_if_time_expired(time(), true);
78 // If the attempt is already closed, redirect them to the review page.
79 if ($attemptobj->is_finished()) {
80 redirect($attemptobj->review_url());
83 \core\session\manager
::keepalive(); // Try to prevent sessions expiring during quiz attempts.
85 // Arrange for the navigation to be displayed.
86 if (empty($attemptobj->get_quiz()->showblocks
)) {
87 $PAGE->blocks
->show_only_fake_blocks();
90 $navbc = $attemptobj->get_navigation_panel($output, 'quiz_attempt_nav_panel', -1);
91 $regions = $PAGE->blocks
->get_regions();
92 $PAGE->blocks
->add_fake_block($navbc, reset($regions));
94 $PAGE->navbar
->add(get_string('summaryofattempt', 'quiz'));
95 $PAGE->set_title($attemptobj->summary_page_title());
96 $PAGE->set_heading($attemptobj->get_course()->fullname
);
97 $PAGE->activityheader
->disable();
99 echo $output->summary_page($attemptobj, $displayoptions);
101 // Log this page view.
102 $attemptobj->fire_attempt_summary_viewed_event();