Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]
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. 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 17 /** 18 * This script controls the display of the quiz reports. 19 * 20 * @package mod_quiz 21 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 define('NO_OUTPUT_BUFFERING', true); 26 27 require_once(__DIR__ . '/../../config.php'); 28 require_once($CFG->dirroot . '/mod/quiz/locallib.php'); 29 require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); 30 require_once($CFG->dirroot . '/mod/quiz/report/default.php'); 31 32 $id = optional_param('id', 0, PARAM_INT); 33 $q = optional_param('q', 0, PARAM_INT); 34 $mode = optional_param('mode', '', PARAM_ALPHA); 35 36 if ($id) { 37 if (!$cm = get_coursemodule_from_id('quiz', $id)) { 38 print_error('invalidcoursemodule'); 39 } 40 if (!$course = $DB->get_record('course', array('id' => $cm->course))) { 41 print_error('coursemisconf'); 42 } 43 if (!$quiz = $DB->get_record('quiz', array('id' => $cm->instance))) { 44 print_error('invalidcoursemodule'); 45 } 46 47 } else { 48 if (!$quiz = $DB->get_record('quiz', array('id' => $q))) { 49 print_error('invalidquizid', 'quiz'); 50 } 51 if (!$course = $DB->get_record('course', array('id' => $quiz->course))) { 52 print_error('invalidcourseid'); 53 } 54 if (!$cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) { 55 print_error('invalidcoursemodule'); 56 } 57 } 58 59 $url = new moodle_url('/mod/quiz/report.php', array('id' => $cm->id)); 60 if ($mode !== '') { 61 $url->param('mode', $mode); 62 } 63 $PAGE->set_url($url); 64 65 require_login($course, false, $cm); 66 $context = context_module::instance($cm->id); 67 $PAGE->set_pagelayout('report'); 68 69 $reportlist = quiz_report_list($context); 70 if (empty($reportlist)) { 71 print_error('erroraccessingreport', 'quiz'); 72 } 73 74 // Validate the requested report name. 75 if ($mode == '') { 76 // Default to first accessible report and redirect. 77 $url->param('mode', reset($reportlist)); 78 redirect($url); 79 } else if (!in_array($mode, $reportlist)) { 80 print_error('erroraccessingreport', 'quiz'); 81 } 82 if (!is_readable("report/$mode/report.php")) { 83 print_error('reportnotfound', 'quiz', '', $mode); 84 } 85 86 // Open the selected quiz report and display it. 87 $file = $CFG->dirroot . '/mod/quiz/report/' . $mode . '/report.php'; 88 if (is_readable($file)) { 89 include_once($file); 90 } 91 $reportclassname = 'quiz_' . $mode . '_report'; 92 if (!class_exists($reportclassname)) { 93 print_error('preprocesserror', 'quiz'); 94 } 95 96 $report = new $reportclassname(); 97 $report->display($quiz, $cm, $course); 98 99 // Print footer. 100 echo $OUTPUT->footer(); 101 102 // Log that this report was viewed. 103 $params = array( 104 'context' => $context, 105 'other' => array( 106 'quizid' => $quiz->id, 107 'reportname' => $mode 108 ) 109 ); 110 $event = \mod_quiz\event\report_viewed::create($params); 111 $event->add_record_snapshot('course', $course); 112 $event->add_record_snapshot('quiz', $quiz); 113 $event->trigger();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body