[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/scorm/report/ -> userreporttracks.php (source)

   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  $attempt = optional_param('attempt', 1, PARAM_INT); // attempt number.
  33  $download = optional_param('download', '', PARAM_ALPHA);
  34  
  35  // Building the url to use for links.+ data details buildup.
  36  $url = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $id,
  37      'user' => $userid,
  38      'attempt' => $attempt,
  39      'scoid' => $scoid));
  40  $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
  41  $course = get_course($cm->course);
  42  $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
  43  $user = $DB->get_record('user', array('id' => $userid), user_picture::fields(), MUST_EXIST);
  44  $selsco = $DB->get_record('scorm_scoes', array('id' => $scoid), '*', MUST_EXIST);
  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  // Trigger a tracks viewed event.
  55  $event = \mod_scorm\event\tracks_viewed::create(array(
  56      'context' => $contextmodule,
  57      'relateduserid' => $userid,
  58      'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id, 'scoid' => $scoid)
  59  ));
  60  $event->add_record_snapshot('course_modules', $cm);
  61  $event->add_record_snapshot('scorm', $scorm);
  62  $event->trigger();
  63  
  64  // Print the page header.
  65  $strreport = get_string('report', 'scorm');
  66  $strattempt = get_string('attempt', 'scorm');
  67  
  68  $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
  69  $PAGE->set_heading($course->fullname);
  70  $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
  71  $PAGE->navbar->add("$strattempt $attempt - ".fullname($user),
  72      new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id, 'user' => $userid, 'attempt' => $attempt)));
  73  $PAGE->navbar->add($selsco->title . ' - '. get_string('details', 'scorm'));
  74  
  75  if ($trackdata = scorm_get_tracks($selsco->id, $userid, $attempt)) {
  76      if ($trackdata->status == '') {
  77          $trackdata->status = 'notattempted';
  78      }
  79  } else {
  80      $trackdata = new stdClass();
  81      $trackdata->status = 'notattempted';
  82      $trackdata->total_time = '';
  83  }
  84  
  85  $courseshortname = format_string($course->shortname, true,
  86      array('context' => context_course::instance($course->id)));
  87  $exportfilename = $courseshortname . '-' . format_string($scorm->name, true) . '-' . get_string('details', 'scorm');
  88  
  89  $table = new flexible_table('mod_scorm-userreporttracks');
  90  
  91  if (!$table->is_downloading($download, $exportfilename)) {
  92      echo $OUTPUT->header();
  93      echo $OUTPUT->heading(format_string($scorm->name));
  94      $currenttab = '';
  95      require($CFG->dirroot . '/mod/scorm/report/userreporttabs.php');
  96      echo $OUTPUT->box_start('generalbox boxaligncenter');
  97      echo $OUTPUT->heading("$strattempt $attempt - ". fullname($user).': '.
  98      format_string($selsco->title). ' - '. get_string('details', 'scorm'), 3);
  99  }
 100  $table->define_baseurl($PAGE->url);
 101  $table->define_columns(array('element', 'value'));
 102  $table->define_headers(array(get_string('element', 'scorm'), get_string('value', 'scorm')));
 103  $table->set_attribute('class', 'generaltable generalbox boxaligncenter scormtrackreport');
 104  $table->show_download_buttons_at(array(TABLE_P_BOTTOM));
 105  $table->setup();
 106  
 107  foreach ($trackdata as $element => $value) {
 108      if (substr($element, 0, 3) == 'cmi') {
 109          $existelements = true;
 110          $row = array();
 111          $string = false;
 112          if (stristr($element, '.id') !== false) {
 113              $string = "trackid";
 114          } else if (stristr($element, '.result') !== false) {
 115              $string = "trackresult";
 116          } else if (stristr($element, '.student_response') !== false or // SCORM 1.2 value.
 117              stristr($element, '.learner_response') !== false) { // SCORM 2004 value.
 118              $string = "trackresponse";
 119          } else if (stristr($element, '.type') !== false) {
 120              $string = "tracktype";
 121          } else if (stristr($element, '.weighting') !== false) {
 122              $string = "trackweight";
 123          } else if (stristr($element, '.time') !== false) {
 124              $string = "tracktime";
 125          } else if (stristr($element, '.correct_responses._count') !== false) {
 126              $string = "trackcorrectcount";
 127          } else if (stristr($element, '.score.min') !== false) {
 128              $string = "trackscoremin";
 129          } else if (stristr($element, '.score.max') !== false) {
 130              $string = "trackscoremax";
 131          } else if (stristr($element, '.score.raw') !== false) {
 132              $string = "trackscoreraw";
 133          } else if (stristr($element, '.latency') !== false) {
 134              $string = "tracklatency";
 135          } else if (stristr($element, '.pattern') !== false) {
 136              $string = "trackpattern";
 137          } else if (stristr($element, '.suspend_data') !== false) {
 138              $string = "tracksuspenddata";
 139          }
 140  
 141          if (empty($string) || $table->is_downloading()) {
 142              $row[] = $element;
 143          } else {
 144              $row[] = $element.$OUTPUT->help_icon($string, 'scorm');
 145          }
 146          if (strpos($element, '_time') === false) {
 147              $row[] = s($value);
 148          } else {
 149              $row[] = s(scorm_format_duration($value));
 150          }
 151          $table->add_data($row);
 152      }
 153  }
 154  $table->finish_output();
 155  if (!$table->is_downloading()) {
 156      echo $OUTPUT->box_end();
 157      echo $OUTPUT->footer();
 158  }
 159  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1