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 script controls the display of the quiz reports.
21 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 use mod_quiz\quiz_settings
;
27 define('NO_OUTPUT_BUFFERING', true);
29 require_once(__DIR__
. '/../../config.php');
30 require_once($CFG->dirroot
. '/mod/quiz/locallib.php');
31 require_once($CFG->dirroot
. '/mod/quiz/report/reportlib.php');
33 $id = optional_param('id', 0, PARAM_INT
);
34 $q = optional_param('q', 0, PARAM_INT
);
35 $mode = optional_param('mode', '', PARAM_ALPHA
);
38 $quizobj = quiz_settings
::create_for_cmid($id);
40 $quizobj = quiz_settings
::create($q);
42 $quiz = $quizobj->get_quiz();
43 $cm = $quizobj->get_cm();
44 $course = $quizobj->get_course();
46 $url = new moodle_url('/mod/quiz/report.php', ['id' => $cm->id
]);
48 $url->param('mode', $mode);
52 require_login($course, false, $cm);
53 $PAGE->set_pagelayout('report');
54 $PAGE->activityheader
->disable();
55 $reportlist = quiz_report_list($quizobj->get_context());
56 if (empty($reportlist)) {
57 throw new \
moodle_exception('erroraccessingreport', 'quiz');
60 // Validate the requested report name.
62 // Default to first accessible report and redirect.
63 $url->param('mode', reset($reportlist));
65 } else if (!in_array($mode, $reportlist)) {
66 throw new \
moodle_exception('erroraccessingreport', 'quiz');
68 if (!is_readable("report/$mode/report.php")) {
69 throw new \
moodle_exception('reportnotfound', 'quiz', '', $mode);
72 // Open the selected quiz report and display it.
73 $file = $CFG->dirroot
. '/mod/quiz/report/' . $mode . '/report.php';
74 if (is_readable($file)) {
77 $reportclassname = 'quiz_' . $mode . '_report';
78 if (!class_exists($reportclassname)) {
79 throw new \
moodle_exception('preprocesserror', 'quiz');
82 $report = new $reportclassname();
83 $report->display($quiz, $cm, $course);
86 echo $OUTPUT->footer();
88 // Log that this report was viewed.
90 'context' => $quizobj->get_context(),
92 'quizid' => $quiz->id
,
96 $event = \mod_quiz\event\report_viewed
::create($params);
97 $event->add_record_snapshot('course', $course);
98 $event->add_record_snapshot('quiz', $quiz);