Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   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  
  28  $id = required_param('id', PARAM_INT); // Course Module ID.
  29  $userid = required_param('user', PARAM_INT); // User ID.
  30  $attempt = optional_param('attempt', 1, PARAM_INT); // attempt number.
  31  
  32  // Building the url to use for links.+ data details buildup.
  33  $url = new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id,
  34                                                                  'user' => $userid,
  35                                                                  'attempt' => $attempt));
  36  $tracksurl = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $id,
  37                                                                              'user' => $userid,
  38                                                                              'attempt' => $attempt));
  39  $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
  40  $course = get_course($cm->course);
  41  $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
  42  $user = $DB->get_record('user', array('id' => $userid), implode(',', \core_user\fields::get_picture_fields()), MUST_EXIST);
  43  // Get list of attempts this user has made.
  44  $attemptids = scorm_get_all_attempts($scorm->id, $userid);
  45  
  46  $PAGE->set_url($url);
  47  // END of url setting + data buildup.
  48  
  49  // Checking login +logging +getting context.
  50  require_login($course, false, $cm);
  51  $contextmodule = context_module::instance($cm->id);
  52  require_capability('mod/scorm:viewreport', $contextmodule);
  53  
  54  // Check user has group access.
  55  if (!groups_user_groups_visible($course, $userid, $cm)) {
  56      throw new moodle_exception('nopermissiontoshow');
  57  }
  58  
  59  // Trigger a user report viewed event.
  60  $event = \mod_scorm\event\user_report_viewed::create(array(
  61      'context' => $contextmodule,
  62      'relateduserid' => $userid,
  63      'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id)
  64  ));
  65  $event->add_record_snapshot('course_modules', $cm);
  66  $event->add_record_snapshot('scorm', $scorm);
  67  $event->trigger();
  68  
  69  // Print the page header.
  70  $strreport = get_string('report', 'scorm');
  71  $strattempt = get_string('attempt', 'scorm');
  72  
  73  $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
  74  $PAGE->set_heading($course->fullname);
  75  $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
  76  $PAGE->navbar->add(fullname($user). " - $strattempt $attempt");
  77  
  78  echo $OUTPUT->header();
  79  echo $OUTPUT->heading(format_string($scorm->name));
  80  // End of Print the page header.
  81  $currenttab = 'scoes';
  82  require($CFG->dirroot . '/mod/scorm/report/userreporttabs.php');
  83  
  84  // Printing user details.
  85  $output = $PAGE->get_renderer('mod_scorm');
  86  echo $output->view_user_heading($user, $course, $PAGE->url, $attempt, $attemptids);
  87  
  88  if ($scoes = $DB->get_records('scorm_scoes', array('scorm' => $scorm->id), 'sortorder, id')) {
  89      // Print general score data.
  90      $table = new html_table();
  91      $table->head = array(
  92              get_string('title', 'scorm'),
  93              get_string('status', 'scorm'),
  94              get_string('time', 'scorm'),
  95              get_string('score', 'scorm'),
  96              '');
  97      $table->align = array('left', 'center', 'center', 'right', 'left');
  98      $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
  99      $table->width = '80%';
 100      $table->size = array('*', '*', '*', '*', '*');
 101      foreach ($scoes as $sco) {
 102          if ($sco->launch != '') {
 103              $row = array();
 104              $score = '&nbsp;';
 105              if ($trackdata = scorm_get_tracks($sco->id, $userid, $attempt)) {
 106                  if ($trackdata->score_raw != '') {
 107                      $score = $trackdata->score_raw;
 108                  }
 109                  if ($trackdata->status == '') {
 110                      if (!empty($trackdata->progress)) {
 111                          $trackdata->status = $trackdata->progress;
 112                      } else {
 113                          $trackdata->status = 'notattempted';
 114                      }
 115                  }
 116                  $tracksurl->param('scoid', $sco->id);
 117                  $detailslink = html_writer::link($tracksurl, get_string('details', 'scorm'));
 118              } else {
 119                  $trackdata = new stdClass();
 120                  $trackdata->status = 'notattempted';
 121                  $trackdata->total_time = '&nbsp;';
 122                  $detailslink = '&nbsp;';
 123              }
 124              $strstatus = get_string($trackdata->status, 'scorm');
 125              $row[] = $OUTPUT->pix_icon($trackdata->status, $strstatus, 'scorm') . '&nbsp;'.format_string($sco->title);
 126              $row[] = get_string($trackdata->status, 'scorm');
 127              $row[] = scorm_format_duration($trackdata->total_time);
 128              $row[] = $score;
 129              $row[] = $detailslink;
 130          } else {
 131              $row = array(format_string($sco->title), '&nbsp;', '&nbsp;', '&nbsp;', '&nbsp;');
 132          }
 133          $table->data[] = $row;
 134      }
 135      echo html_writer::table($table);
 136  }
 137  
 138  // Print footer.
 139  
 140  echo $OUTPUT->footer();