MDL-80880 quiz: change display of previous attempts summary
[moodle.git] / mod / quiz / reviewquestion.php
blob54f1519c7aa7d88ac73a71e30d0f362b08c6b43a
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.
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/>.
17 /**
18 * This page prints a review of a particular question attempt.
19 * This page is expected to only be used in a popup window.
21 * @package mod_quiz
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 use mod_quiz\output\attempt_summary_information;
28 require_once(__DIR__ . '/../../config.php');
29 require_once('locallib.php');
31 $attemptid = required_param('attempt', PARAM_INT);
32 $slot = required_param('slot', PARAM_INT);
33 $seq = optional_param('step', null, PARAM_INT);
34 $cmid = optional_param('cmid', null, PARAM_INT);
36 $baseurl = new moodle_url('/mod/quiz/reviewquestion.php',
37 ['attempt' => $attemptid, 'slot' => $slot]);
38 $currenturl = new moodle_url($baseurl);
39 if (!is_null($seq)) {
40 $currenturl->param('step', $seq);
42 $PAGE->set_url($currenturl);
44 $attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
45 $attemptobj->preload_all_attempt_step_users();
47 // Check login.
48 require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
49 $attemptobj->check_review_capability();
50 $student = $DB->get_record('user', ['id' => $attemptobj->get_userid()]);
52 $accessmanager = $attemptobj->get_access_manager(time());
53 $options = $attemptobj->get_display_options(true);
55 $PAGE->set_pagelayout('popup');
56 $PAGE->set_title(get_string('reviewofquestion', 'quiz', [
57 'question' => format_string($attemptobj->get_question_name($slot)),
58 'quiz' => format_string($attemptobj->get_quiz_name()), 'user' => fullname($student)]));
59 $PAGE->set_heading($attemptobj->get_course()->fullname);
60 $output = $PAGE->get_renderer('mod_quiz');
62 // Check permissions - warning there is similar code in review.php and
63 // quiz_attempt::check_file_access. If you change on, change them all.
64 if ($attemptobj->is_own_attempt()) {
65 if (!$attemptobj->is_finished()) {
66 echo $output->review_question_not_allowed($attemptobj, get_string('cannotreviewopen', 'quiz'));
67 die();
68 } else if (!$options->attempt) {
69 echo $output->review_question_not_allowed($attemptobj,
70 $attemptobj->cannot_review_message());
71 die();
74 } else if (!$attemptobj->is_review_allowed()) {
75 throw new moodle_exception('noreviewattempt', 'quiz', $attemptobj->view_url());
78 // Prepare summary informat about this question attempt.
79 $summary = new attempt_summary_information();
81 // Student name.
82 $userpicture = new user_picture($student);
83 $userpicture->courseid = $attemptobj->get_courseid();
84 $summary->add_item('user', $userpicture,
85 new action_link(new moodle_url('/user/view.php', ['id' => $student->id, 'course' => $attemptobj->get_courseid()]),
86 fullname($student, true)));
88 // Quiz name.
89 $summary->add_item('quizname', get_string('modulename', 'quiz'),
90 format_string($attemptobj->get_quiz_name()));
92 // Question name.
93 $summary->add_item('questionname', get_string('question', 'quiz'),
94 format_string($attemptobj->get_question_name($slot)));
96 // Other attempts at the quiz.
97 if ($attemptobj->has_capability('mod/quiz:viewreports')) {
98 $otherattemptsurl = clone($baseurl);
99 $otherattemptsurl->param('slot', $attemptobj->get_original_slot($slot));
100 $attemptlist = $attemptobj->links_to_other_attempts($otherattemptsurl);
101 if ($attemptlist) {
102 $summary->add_item('attemptlist', get_string('attempts', 'quiz'), $attemptlist);
106 // Timestamp of this action.
107 $timestamp = $attemptobj->get_question_action_time($slot);
108 if ($timestamp) {
109 $summary->add_item('timestamp', get_string('completedon', 'quiz'), userdate($timestamp));
112 echo $output->review_question_page($attemptobj, $slot, $seq,
113 $attemptobj->get_display_options(true), $summary);