MDL-45144 convert book events to create_from_xxx() helpers
[moodle.git] / mod / scorm / report.php
blob69524896a59bc2f0d3668ff8922f4f8633079f37
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 // This script uses installed report plugins to print scorm reports
19 require_once("../../config.php");
20 require_once($CFG->libdir.'/tablelib.php');
21 require_once($CFG->dirroot.'/mod/scorm/locallib.php');
22 require_once($CFG->dirroot.'/mod/scorm/reportsettings_form.php');
23 require_once($CFG->dirroot.'/mod/scorm/report/reportlib.php');
24 require_once($CFG->libdir.'/formslib.php');
25 require_once($CFG->dirroot.'/mod/scorm/report/default.php'); // Parent class
26 define('SCORM_REPORT_DEFAULT_PAGE_SIZE', 20);
27 define('SCORM_REPORT_ATTEMPTS_ALL_STUDENTS', 0);
28 define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH', 1);
29 define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 2);
31 $id = required_param('id', PARAM_INT);// Course Module ID, or
32 $download = optional_param('download', '', PARAM_RAW);
33 $mode = optional_param('mode', '', PARAM_ALPHA); // Report mode
35 $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
36 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
37 $scorm = $DB->get_record('scorm', array('id'=>$cm->instance), '*', MUST_EXIST);
39 $contextmodule = context_module::instance($cm->id);
40 $reportlist = scorm_report_list($contextmodule);
42 $url = new moodle_url('/mod/scorm/report.php');
44 $url->param('id', $id);
45 if (empty($mode)) {
46 $mode = reset($reportlist);
47 } else if (!in_array($mode, $reportlist)) {
48 print_error('erroraccessingreport', 'scorm');
50 $url->param('mode', $mode);
52 $PAGE->set_url($url);
54 require_login($course, false, $cm);
56 require_capability('mod/scorm:viewreport', $contextmodule);
58 if (count($reportlist) < 1) {
59 print_error('erroraccessingreport', 'scorm');
62 // Trigger a report viewed event.
63 $event = \mod_scorm\event\report_viewed::create(array(
64 'objectid' => $scorm->id,
65 'context' => $contextmodule,
66 'other' => array('mode' => $mode)
67 ));
68 $event->add_record_snapshot('course_modules', $cm);
69 $event->add_record_snapshot('scorm', $scorm);
70 $event->trigger();
72 $userdata = null;
73 if (!empty($download)) {
74 $noheader = true;
76 /// Print the page header
77 if (empty($noheader)) {
78 $strreport = get_string('report', 'scorm');
79 $strattempt = get_string('attempt', 'scorm');
81 $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
82 $PAGE->set_heading($course->fullname);
83 $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id'=>$cm->id)));
85 echo $OUTPUT->header();
86 echo $OUTPUT->heading(format_string($scorm->name));
87 $currenttab = 'reports';
88 require($CFG->dirroot . '/mod/scorm/tabs.php');
91 // Open the selected Scorm report and display it
92 $reportclassname = "scorm_{$mode}_report";
93 $report = new $reportclassname();
94 $report->display($scorm, $cm, $course, $download); // Run the report!
96 // Print footer
98 if (empty($noheader)) {
99 echo $OUTPUT->footer();