2009-10-16 03:20:38 +00:00
|
|
|
<?php
|
2011-02-08 15:02:23 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2008-06-27 18:04:48 +00:00
|
|
|
/**
|
|
|
|
* This page prints a summary of a quiz attempt before it is submitted.
|
|
|
|
*
|
2011-02-21 16:13:25 +00:00
|
|
|
* @package mod
|
2011-02-08 15:02:23 +00:00
|
|
|
* @subpackage quiz
|
2011-02-21 16:13:25 +00:00
|
|
|
* @copyright 2009 The Open University
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2008-06-27 18:04:48 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-21 16:13:25 +00:00
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
require_once(dirname(__FILE__) . '/../../config.php');
|
|
|
|
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
2008-06-27 18:04:48 +00:00
|
|
|
|
|
|
|
$attemptid = required_param('attempt', PARAM_INT); // The attempt to summarise.
|
2009-10-16 03:20:38 +00:00
|
|
|
|
2010-08-04 16:31:54 +00:00
|
|
|
$PAGE->set_url('/mod/quiz/summary.php', array('attempt' => $attemptid));
|
2009-10-16 03:20:38 +00:00
|
|
|
|
2010-03-08 16:01:38 +00:00
|
|
|
$attemptobj = quiz_attempt::create($attemptid);
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Check login.
|
2010-05-21 03:15:48 +00:00
|
|
|
require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2012-11-30 11:53:38 +00:00
|
|
|
// Check that this attempt belongs to this user.
|
2008-06-27 18:04:48 +00:00
|
|
|
if ($attemptobj->get_userid() != $USER->id) {
|
2012-11-30 11:53:38 +00:00
|
|
|
if ($attemptobj->has_capability('mod/quiz:viewreports')) {
|
2012-12-12 08:12:16 +00:00
|
|
|
redirect($attemptobj->review_url(null));
|
2012-11-30 11:53:38 +00:00
|
|
|
} else {
|
|
|
|
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt');
|
|
|
|
}
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Check capabilites.
|
|
|
|
if (!$attemptobj->is_preview_user()) {
|
|
|
|
$attemptobj->require_capability('mod/quiz:attempt');
|
|
|
|
}
|
|
|
|
|
2010-08-04 16:31:54 +00:00
|
|
|
if ($attemptobj->is_preview_user()) {
|
2010-08-06 05:49:47 +00:00
|
|
|
navigation_node::override_active_url($attemptobj->start_attempt_url());
|
2010-08-04 16:31:54 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Check access.
|
2008-06-27 18:04:48 +00:00
|
|
|
$accessmanager = $attemptobj->get_access_manager(time());
|
2012-07-12 18:39:01 +01:00
|
|
|
$accessmanager->setup_attempt_page($PAGE);
|
2012-09-06 17:35:40 +08:00
|
|
|
$output = $PAGE->get_renderer('mod_quiz');
|
2012-07-12 18:39:01 +01:00
|
|
|
$messages = $accessmanager->prevent_access();
|
2008-06-30 16:56:49 +00:00
|
|
|
if (!$attemptobj->is_preview_user() && $messages) {
|
2008-06-27 18:04:48 +00:00
|
|
|
print_error('attempterror', 'quiz', $attemptobj->view_url(),
|
2011-11-10 12:51:24 +00:00
|
|
|
$output->access_messages($messages));
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
2011-10-07 17:43:15 +01:00
|
|
|
if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) {
|
|
|
|
redirect($attemptobj->start_attempt_url(null, $page));
|
|
|
|
}
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
$displayoptions = $attemptobj->get_display_options(false);
|
|
|
|
|
2012-06-07 19:17:07 +01:00
|
|
|
// If the attempt is now overdue, or abandoned, deal with that.
|
|
|
|
$attemptobj->handle_if_time_expired(time(), true);
|
|
|
|
|
|
|
|
// If the attempt is already closed, redirect them to the review page.
|
|
|
|
if ($attemptobj->is_finished()) {
|
|
|
|
redirect($attemptobj->review_url());
|
|
|
|
}
|
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Log this page view.
|
2011-04-04 20:11:29 +01:00
|
|
|
add_to_log($attemptobj->get_courseid(), 'quiz', 'view summary',
|
|
|
|
'summary.php?attempt=' . $attemptobj->get_attemptid(),
|
2008-06-27 18:04:48 +00:00
|
|
|
$attemptobj->get_quizid(), $attemptobj->get_cmid());
|
|
|
|
|
2011-10-17 12:06:44 +01:00
|
|
|
// Arrange for the navigation to be displayed.
|
2010-05-21 03:15:48 +00:00
|
|
|
if (empty($attemptobj->get_quiz()->showblocks)) {
|
|
|
|
$PAGE->blocks->show_only_fake_blocks();
|
|
|
|
}
|
|
|
|
|
2011-10-18 08:39:28 +01:00
|
|
|
$navbc = $attemptobj->get_navigation_panel($output, 'quiz_attempt_nav_panel', -1);
|
2012-04-18 08:55:12 +01:00
|
|
|
$regions = $PAGE->blocks->get_regions();
|
|
|
|
$PAGE->blocks->add_fake_block($navbc, reset($regions));
|
2011-10-17 12:06:44 +01:00
|
|
|
|
2011-10-05 20:58:38 +01:00
|
|
|
$PAGE->navbar->add(get_string('summaryofattempt', 'quiz'));
|
|
|
|
$PAGE->set_title(format_string($attemptobj->get_quiz_name()));
|
|
|
|
$PAGE->set_heading($attemptobj->get_course()->fullname);
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2011-10-17 12:06:44 +01:00
|
|
|
// Display the page.
|
2011-09-21 15:31:12 +01:00
|
|
|
echo $output->summary_page($attemptobj, $displayoptions);
|