MDL-38647 quiz review question issues
[moodle.git] / mod / quiz / reviewquestion.php
CommitLineData
a09f21d0 1<?php
729c372b
TH
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
ee1fb969 17/**
b55797b8 18 * This page prints a review of a particular question attempt.
19 * This page is expected to only be used in a popup window.
f63a4ff2 20 *
ba643847 21 * @package mod
729c372b 22 * @subpackage quiz
ba643847
TH
23 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
f63a4ff2 25 */
ee1fb969 26
ba643847 27
729c372b
TH
28require_once(dirname(__FILE__) . '/../../config.php');
29require_once('locallib.php');
30
9e83f3d1
TH
31$attemptid = required_param('attempt', PARAM_INT);
32$slot = required_param('slot', PARAM_INT);
33$seq = optional_param('step', null, PARAM_INT);
729c372b
TH
34
35$baseurl = new moodle_url('/mod/quiz/reviewquestion.php',
36 array('attempt' => $attemptid, 'slot' => $slot));
37$currenturl = new moodle_url($baseurl);
2515be0e 38if (!is_null($seq)) {
729c372b
TH
39 $currenturl->param('step', $seq);
40}
41$PAGE->set_url($currenturl);
729c372b
TH
42
43$attemptobj = quiz_attempt::create($attemptid);
44
45// Check login.
cdbea7ee 46require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
729c372b
TH
47$attemptobj->check_review_capability();
48
c3584ad6
TH
49$accessmanager = $attemptobj->get_access_manager(time());
50$options = $attemptobj->get_display_options(true);
51
3a5da40b
TH
52$PAGE->set_pagelayout('popup');
53$output = $PAGE->get_renderer('mod_quiz');
2daffca5 54
8032cd79
TH
55// Check permissions.
56if ($attemptobj->is_own_attempt()) {
729c372b 57 if (!$attemptobj->is_finished()) {
3a5da40b 58 echo $output->review_question_not_allowed(get_string('cannotreviewopen', 'quiz'));
2daffca5 59 die();
c3584ad6 60 } else if (!$options->attempt) {
3a5da40b 61 echo $output->review_question_not_allowed(
d755b0f5 62 $attemptobj->cannot_review_message());
2daffca5 63 die();
7bbe08a2 64 }
729c372b 65
8032cd79
TH
66} else if (!$attemptobj->is_review_allowed()) {
67 throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreviewattempt');
729c372b
TH
68}
69
3a5da40b
TH
70// Prepare summary informat about this question attempt.
71$summarydata = array();
72
729c372b 73// Quiz name.
3a5da40b
TH
74$summarydata['quizname'] = array(
75 'title' => get_string('modulename', 'quiz'),
76 'content' => format_string($attemptobj->get_quiz_name()),
77);
729c372b
TH
78
79// Question name.
3a5da40b
TH
80$summarydata['questionname'] = array(
81 'title' => get_string('question', 'quiz'),
82 'content' => $attemptobj->get_question_name($slot),
83);
729c372b
TH
84
85// Other attempts at the quiz.
86if ($attemptobj->has_capability('mod/quiz:viewreports')) {
87 $attemptlist = $attemptobj->links_to_other_attempts($baseurl);
88 if ($attemptlist) {
3a5da40b
TH
89 $summarydata['attemptlist'] = array(
90 'title' => get_string('attempts', 'quiz'),
91 'content' => $attemptlist,
92 );
aafdb447 93 }
729c372b
TH
94}
95
96// Timestamp of this action.
97$timestamp = $attemptobj->get_question_action_time($slot);
98if ($timestamp) {
3a5da40b
TH
99 $summarydata['timestamp'] = array(
100 'title' => get_string('completedon', 'quiz'),
101 'content' => userdate($timestamp),
102 );
729c372b
TH
103}
104
3a5da40b
TH
105echo $output->review_question_page($attemptobj, $slot, $seq,
106 $attemptobj->get_display_options(true), $summarydata);