MDL-30431 behat: Fixed wiki behat
[moodle.git] / mod / scorm / report.php
blobbbad079b1743c642e937ccb7e639170ccb12519a
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 'context' => $contextmodule,
65 'other' => array(
66 'scormid' => $scorm->id,
67 'mode' => $mode
69 ));
70 $event->add_record_snapshot('course_modules', $cm);
71 $event->add_record_snapshot('scorm', $scorm);
72 $event->trigger();
74 $userdata = null;
75 if (!empty($download)) {
76 $noheader = true;
78 /// Print the page header
79 if (empty($noheader)) {
80 $strreport = get_string('report', 'scorm');
81 $strattempt = get_string('attempt', 'scorm');
83 $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
84 $PAGE->set_heading($course->fullname);
85 $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id'=>$cm->id)));
87 echo $OUTPUT->header();
88 echo $OUTPUT->heading(format_string($scorm->name));
89 $currenttab = 'reports';
90 require($CFG->dirroot . '/mod/scorm/tabs.php');
93 // Open the selected Scorm report and display it
94 $reportclassname = "scorm_{$mode}_report";
95 $report = new $reportclassname();
96 $report->display($scorm, $cm, $course, $download); // Run the report!
98 // Print footer
100 if (empty($noheader)) {
101 echo $OUTPUT->footer();