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]

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