Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   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 page displays the user data from a single attempt
  19   *
  20   * @package mod_scorm
  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  require_once("../../../config.php");
  26  require_once($CFG->dirroot.'/mod/scorm/locallib.php');
  27  require_once($CFG->libdir.'/tablelib.php');
  28  
  29  $id = required_param('id', PARAM_INT); // Course Module ID.
  30  $userid = required_param('user', PARAM_INT); // User ID.
  31  $scoid = required_param('scoid', PARAM_INT); // SCO ID.
  32  $mode = required_param('mode', PARAM_ALPHA); // Scorm mode.
  33  $attempt = optional_param('attempt', 1, PARAM_INT); // attempt number.
  34  $download = optional_param('download', '', PARAM_ALPHA);
  35  
  36  // Building the url to use for links.+ data details buildup.
  37  $url = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $id,
  38      'user' => $userid,
  39      'attempt' => $attempt,
  40      'scoid' => $scoid,
  41      'mode' => $mode));
  42  $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
  43  $course = get_course($cm->course);
  44  $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
  45  $user = $DB->get_record('user', array('id' => $userid), implode(',', \core_user\fields::get_picture_fields()), MUST_EXIST);
  46  $selsco = $DB->get_record('scorm_scoes', array('id' => $scoid), '*', MUST_EXIST);
  47  
  48  $PAGE->set_url($url);
  49  // END of url setting + data buildup.
  50  
  51  // Checking login +logging +getting context.
  52  require_login($course, false, $cm);
  53  $contextmodule = context_module::instance($cm->id);
  54  require_capability('mod/scorm:viewreport', $contextmodule);
  55  
  56  // Check user has group access.
  57  if (!groups_user_groups_visible($course, $userid, $cm)) {
  58      throw new moodle_exception('nopermissiontoshow');
  59  }
  60  
  61  // Trigger a tracks viewed event.
  62  $event = \mod_scorm\event\tracks_viewed::create(array(
  63      'context' => $contextmodule,
  64      'relateduserid' => $userid,
  65      'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id, 'scoid' => $scoid, 'mode' => $mode)
  66  ));
  67  $event->add_record_snapshot('course_modules', $cm);
  68  $event->add_record_snapshot('scorm', $scorm);
  69  $event->trigger();
  70  
  71  // Print the page header.
  72  $strreport = get_string('report', 'scorm');
  73  $strattempt = get_string('attempt', 'scorm');
  74  
  75  $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
  76  $PAGE->set_heading($course->fullname);
  77  $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
  78  $PAGE->navbar->add("$strattempt $attempt - ".fullname($user),
  79      new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id, 'user' => $userid, 'attempt' => $attempt)));
  80  $PAGE->navbar->add($selsco->title . ' - '. get_string('details', 'scorm'));
  81  $PAGE->set_secondary_active_tab('scormreport');
  82  
  83  if ($trackdata = scorm_get_tracks($selsco->id, $userid, $attempt)) {
  84      if ($trackdata->status == '') {
  85          $trackdata->status = 'notattempted';
  86      }
  87  } else {
  88      $trackdata = new stdClass();
  89      $trackdata->status = 'notattempted';
  90      $trackdata->total_time = '';
  91  }
  92  
  93  $courseshortname = format_string($course->shortname, true,
  94      array('context' => context_course::instance($course->id)));
  95  $exportfilename = $courseshortname . '-' . format_string($scorm->name, true) . '-' . get_string('details', 'scorm');
  96  
  97  $table = new flexible_table('mod_scorm-userreporttracks');
  98  
  99  if (!$table->is_downloading($download, $exportfilename)) {
 100      $PAGE->activityheader->set_attrs([
 101          'hidecompletion' => true,
 102          'description' => ''
 103      ]);
 104      echo $OUTPUT->header();
 105      $currenttab = '';
 106      $renderer = $PAGE->get_renderer('mod_scorm');
 107      $useractionreport = new \mod_scorm\output\userreportsactionbar($id, $userid, $attempt, 'attempt', $mode, $scoid);
 108      echo $renderer->user_report_actionbar($useractionreport);
 109      echo $OUTPUT->box_start('generalbox boxaligncenter');
 110      echo $OUTPUT->heading("$strattempt $attempt - ". fullname($user).': '.
 111      format_string($selsco->title). ' - '. get_string('details', 'scorm'), 3);
 112  }
 113  $table->define_baseurl($PAGE->url);
 114  $table->define_columns(array('element', 'value'));
 115  $table->define_headers(array(get_string('element', 'scorm'), get_string('value', 'scorm')));
 116  $table->set_attribute('class', 'generaltable generalbox boxaligncenter scormtrackreport');
 117  $table->show_download_buttons_at(array(TABLE_P_BOTTOM));
 118  $table->setup();
 119  
 120  foreach ($trackdata as $element => $value) {
 121      if (substr($element, 0, 3) == 'cmi') {
 122          $existelements = true;
 123          $row = array();
 124          $string = false;
 125          if (stristr($element, '.id') !== false) {
 126              $string = "trackid";
 127          } else if (stristr($element, '.result') !== false) {
 128              $string = "trackresult";
 129          } else if (stristr($element, '.student_response') !== false or // SCORM 1.2 value.
 130              stristr($element, '.learner_response') !== false) { // SCORM 2004 value.
 131              $string = "trackresponse";
 132          } else if (stristr($element, '.type') !== false) {
 133              $string = "tracktype";
 134          } else if (stristr($element, '.weighting') !== false) {
 135              $string = "trackweight";
 136          } else if (stristr($element, '.time') !== false) {
 137              $string = "tracktime";
 138          } else if (stristr($element, '.correct_responses._count') !== false) {
 139              $string = "trackcorrectcount";
 140          } else if (stristr($element, '.score.min') !== false) {
 141              $string = "trackscoremin";
 142          } else if (stristr($element, '.score.max') !== false) {
 143              $string = "trackscoremax";
 144          } else if (stristr($element, '.score.raw') !== false) {
 145              $string = "trackscoreraw";
 146          } else if (stristr($element, '.latency') !== false) {
 147              $string = "tracklatency";
 148          } else if (stristr($element, '.pattern') !== false) {
 149              $string = "trackpattern";
 150          } else if (stristr($element, '.suspend_data') !== false) {
 151              $string = "tracksuspenddata";
 152          }
 153  
 154          if (empty($string) || $table->is_downloading()) {
 155              $row[] = s($element);
 156          } else {
 157              $row[] = s($element) . $OUTPUT->help_icon($string, 'scorm');
 158          }
 159          if (strpos($element, '_time') === false) {
 160              $row[] = s($value);
 161          } else {
 162              $row[] = s(scorm_format_duration($value));
 163          }
 164          $table->add_data($row);
 165      }
 166  }
 167  $table->finish_output();
 168  if (!$table->is_downloading()) {
 169      echo $OUTPUT->box_end();
 170      echo $OUTPUT->footer();
 171  }
 172