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] [Versions 401 and 403]

   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->dirroot.'/mod/scorm/report/reportlib.php');
  28  require_once($CFG->libdir . '/tablelib.php');
  29  
  30  $id = required_param('id', PARAM_INT); // Course Module ID.
  31  $userid = required_param('user', PARAM_INT); // User ID.
  32  $attempt = optional_param('attempt', 1, PARAM_INT); // attempt number.
  33  $download = optional_param('download', '', PARAM_ALPHA);
  34  $mode = optional_param('mode', '', PARAM_ALPHA); // Scorm mode from which reached here.
  35  
  36  // Building the url to use for links.+ data details buildup.
  37  $url = new moodle_url('/mod/scorm/report/userreportinteractions.php', array('id' => $id,
  38      'user' => $userid,
  39      'attempt' => $attempt));
  40  
  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 interactions viewed event.
  63  $event = \mod_scorm\event\interactions_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  $trackdata = $DB->get_records('scorm_scoes_track', array('userid' => $user->id, 'scormid' => $scorm->id,
  73      'attempt' => $attempt));
  74  $usertrack = scorm_format_interactions($trackdata);
  75  
  76  $questioncount = get_scorm_question_count($scorm->id);
  77  
  78  $courseshortname = format_string($course->shortname, true,
  79      array('context' => context_course::instance($course->id)));
  80  $exportfilename = $courseshortname . '-' . format_string($scorm->name, true) . '-' . get_string('interactions', 'scorm');
  81  
  82  
  83  // Set up the table.
  84  $table = new flexible_table('mod-scorm-userreport-interactions');
  85  if (!$table->is_downloading($download, $exportfilename)) {
  86  
  87      // Print the page header.
  88      $strattempt = get_string('attempt', 'scorm');
  89      $strreport = get_string('report', 'scorm');
  90  
  91      $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
  92      $PAGE->set_heading($course->fullname);
  93      $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
  94  
  95      $PAGE->navbar->add(fullname($user). " - $strattempt $attempt");
  96  
  97      $PAGE->activityheader->set_attrs([
  98          'hidecompletion' => true,
  99          'description' => ''
 100      ]);
 101  
 102      echo $OUTPUT->header();
 103  
 104      // End of Print the page header.
 105      $currenttab = 'interactions';
 106  
 107      $renderer = $PAGE->get_renderer('mod_scorm');
 108      $useractionreport = new \mod_scorm\output\userreportsactionbar($id, $userid, $attempt, 'interact', $mode);
 109      echo $renderer->user_report_actionbar($useractionreport);
 110  
 111      // Printing user details.
 112      $output = $PAGE->get_renderer('mod_scorm');
 113      echo $output->view_user_heading($user, $course, $PAGE->url, $attempt, $attemptids);
 114  
 115  }
 116  $table->define_baseurl($PAGE->url);
 117  $table->define_columns(array('id', 'studentanswer', 'correctanswer', 'result', 'calcweight'));
 118  $table->define_headers(array(get_string('trackid', 'scorm'), get_string('response', 'scorm'),
 119      get_string('rightanswer', 'scorm'), get_string('result', 'scorm'),
 120      get_string('calculatedweight', 'scorm')));
 121  $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
 122  
 123  $table->show_download_buttons_at(array(TABLE_P_BOTTOM));
 124  $table->setup();
 125  
 126  for ($i = 0; $i < $questioncount; $i++) {
 127      $row = array();
 128      $element = 'cmi.interactions_'.$i.'.id';
 129      if (isset($usertrack->$element)) {
 130          $row[] = s($usertrack->$element);
 131  
 132          $element = 'cmi.interactions_'.$i.'.student_response';
 133          if (isset($usertrack->$element)) {
 134              $row[] = s($usertrack->$element);
 135          } else {
 136              $row[] = '&nbsp;';
 137          }
 138  
 139          $j = 0;
 140          $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
 141          $rightans = '';
 142          if (isset($usertrack->$element)) {
 143              while (isset($usertrack->$element)) {
 144                  if ($j > 0) {
 145                      $rightans .= ',';
 146                  }
 147                  $rightans .= s($usertrack->$element);
 148                  $j++;
 149                  $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
 150              }
 151              $row[] = $rightans;
 152          } else {
 153              $row[] = '&nbsp;';
 154          }
 155          $element = 'cmi.interactions_'.$i.'.result';
 156          $weighting = 'cmi.interactions_'.$i.'.weighting';
 157          if (isset($usertrack->$element)) {
 158              $row[] = s($usertrack->$element);
 159              if ($usertrack->$element == 'correct' &&
 160                  isset($usertrack->$weighting)) {
 161                  $row[] = s($usertrack->$weighting);
 162              } else {
 163                  $row[] = '0';
 164              }
 165          } else {
 166              $row[] = '&nbsp;';
 167          }
 168          $table->add_data($row);
 169      }
 170  }
 171  
 172  $table->finish_output();
 173  
 174  if (!$table->is_downloading()) {
 175      echo $OUTPUT->footer();
 176  }
 177