Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402]

   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  // This script uses installed report plugins to print scorm reports.
  18  
  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  
  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);
  30  
  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.
  34  
  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);
  38  
  39  $contextmodule = context_module::instance($cm->id);
  40  $reportlist = scorm_report_list($contextmodule);
  41  
  42  $url = new moodle_url('/mod/scorm/report.php');
  43  
  44  $url->param('id', $id);
  45  if (empty($mode)) {
  46      $mode = reset($reportlist);
  47  } else if (!in_array($mode, $reportlist)) {
  48      throw new \moodle_exception('erroraccessingreport', 'scorm');
  49  }
  50  $url->param('mode', $mode);
  51  
  52  $PAGE->set_url($url);
  53  
  54  require_login($course, false, $cm);
  55  $PAGE->set_pagelayout('report');
  56  
  57  require_capability('mod/scorm:viewreport', $contextmodule);
  58  
  59  // Activate the secondary nav tab.
  60  navigation_node::override_active_url(new moodle_url('/mod/scorm/report.php', ['id' => $id]));
  61  
  62  if (count($reportlist) < 1) {
  63      throw new \moodle_exception('erroraccessingreport', 'scorm');
  64  }
  65  
  66  // Trigger a report viewed event.
  67  $event = \mod_scorm\event\report_viewed::create(array(
  68      'context' => $contextmodule,
  69      'other' => array(
  70          'scormid' => $scorm->id,
  71          'mode' => $mode
  72      )
  73  ));
  74  $event->add_record_snapshot('course_modules', $cm);
  75  $event->add_record_snapshot('scorm', $scorm);
  76  $event->trigger();
  77  
  78  $userdata = null;
  79  if (!empty($download)) {
  80      $noheader = true;
  81  }
  82  // Print the page header.
  83  if (empty($noheader)) {
  84      $strreport = get_string('report', 'scorm');
  85      $strattempt = get_string('attempt', 'scorm');
  86  
  87      $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
  88      $PAGE->set_heading($course->fullname);
  89      $PAGE->activityheader->set_attrs([
  90          'hidecompletion' => true,
  91          'description' => ''
  92      ]);
  93      $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
  94  
  95      echo $OUTPUT->header();
  96  }
  97  
  98  // Open the selected Scorm report and display it.
  99  $classname = "scormreport_{$mode}\\report";
 100  $legacyclassname = "scorm_{$mode}_report";
 101  $report = class_exists($classname) ? new $classname() : new $legacyclassname();
 102  $report->display($scorm, $cm, $course, $download); // Run the report!
 103  
 104  // Print footer.
 105  
 106  if (empty($noheader)) {
 107      echo $OUTPUT->footer();
 108  }