PageRenderTime 87ms CodeModel.GetById 58ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/scorm/report/userreporttracks.php

https://bitbucket.org/moodle/moodle
PHP | 164 lines | 120 code | 17 blank | 27 comment | 39 complexity | 6568a77a1a5721389f48d6d96d51953e MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  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. * This page displays the user data from a single attempt
  18. *
  19. * @package mod_scorm
  20. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once("../../../config.php");
  24. require_once($CFG->dirroot.'/mod/scorm/locallib.php');
  25. require_once($CFG->libdir.'/tablelib.php');
  26. $id = required_param('id', PARAM_INT); // Course Module ID.
  27. $userid = required_param('user', PARAM_INT); // User ID.
  28. $scoid = required_param('scoid', PARAM_INT); // SCO ID.
  29. $attempt = optional_param('attempt', 1, PARAM_INT); // attempt number.
  30. $download = optional_param('download', '', PARAM_ALPHA);
  31. // Building the url to use for links.+ data details buildup.
  32. $url = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $id,
  33. 'user' => $userid,
  34. 'attempt' => $attempt,
  35. 'scoid' => $scoid));
  36. $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
  37. $course = get_course($cm->course);
  38. $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
  39. $user = $DB->get_record('user', array('id' => $userid), implode(',', \core_user\fields::get_picture_fields()), MUST_EXIST);
  40. $selsco = $DB->get_record('scorm_scoes', array('id' => $scoid), '*', MUST_EXIST);
  41. $PAGE->set_url($url);
  42. // END of url setting + data buildup.
  43. // Checking login +logging +getting context.
  44. require_login($course, false, $cm);
  45. $contextmodule = context_module::instance($cm->id);
  46. require_capability('mod/scorm:viewreport', $contextmodule);
  47. // Check user has group access.
  48. if (!groups_user_groups_visible($course, $userid, $cm)) {
  49. throw new moodle_exception('nopermissiontoshow');
  50. }
  51. // Trigger a tracks viewed event.
  52. $event = \mod_scorm\event\tracks_viewed::create(array(
  53. 'context' => $contextmodule,
  54. 'relateduserid' => $userid,
  55. 'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id, 'scoid' => $scoid)
  56. ));
  57. $event->add_record_snapshot('course_modules', $cm);
  58. $event->add_record_snapshot('scorm', $scorm);
  59. $event->trigger();
  60. // Print the page header.
  61. $strreport = get_string('report', 'scorm');
  62. $strattempt = get_string('attempt', 'scorm');
  63. $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
  64. $PAGE->set_heading($course->fullname);
  65. $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
  66. $PAGE->navbar->add("$strattempt $attempt - ".fullname($user),
  67. new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id, 'user' => $userid, 'attempt' => $attempt)));
  68. $PAGE->navbar->add($selsco->title . ' - '. get_string('details', 'scorm'));
  69. if ($trackdata = scorm_get_tracks($selsco->id, $userid, $attempt)) {
  70. if ($trackdata->status == '') {
  71. $trackdata->status = 'notattempted';
  72. }
  73. } else {
  74. $trackdata = new stdClass();
  75. $trackdata->status = 'notattempted';
  76. $trackdata->total_time = '';
  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('details', 'scorm');
  81. $table = new flexible_table('mod_scorm-userreporttracks');
  82. if (!$table->is_downloading($download, $exportfilename)) {
  83. echo $OUTPUT->header();
  84. echo $OUTPUT->heading(format_string($scorm->name));
  85. $currenttab = '';
  86. require($CFG->dirroot . '/mod/scorm/report/userreporttabs.php');
  87. echo $OUTPUT->box_start('generalbox boxaligncenter');
  88. echo $OUTPUT->heading("$strattempt $attempt - ". fullname($user).': '.
  89. format_string($selsco->title). ' - '. get_string('details', 'scorm'), 3);
  90. }
  91. $table->define_baseurl($PAGE->url);
  92. $table->define_columns(array('element', 'value'));
  93. $table->define_headers(array(get_string('element', 'scorm'), get_string('value', 'scorm')));
  94. $table->set_attribute('class', 'generaltable generalbox boxaligncenter scormtrackreport');
  95. $table->show_download_buttons_at(array(TABLE_P_BOTTOM));
  96. $table->setup();
  97. foreach ($trackdata as $element => $value) {
  98. if (substr($element, 0, 3) == 'cmi') {
  99. $existelements = true;
  100. $row = array();
  101. $string = false;
  102. if (stristr($element, '.id') !== false) {
  103. $string = "trackid";
  104. } else if (stristr($element, '.result') !== false) {
  105. $string = "trackresult";
  106. } else if (stristr($element, '.student_response') !== false or // SCORM 1.2 value.
  107. stristr($element, '.learner_response') !== false) { // SCORM 2004 value.
  108. $string = "trackresponse";
  109. } else if (stristr($element, '.type') !== false) {
  110. $string = "tracktype";
  111. } else if (stristr($element, '.weighting') !== false) {
  112. $string = "trackweight";
  113. } else if (stristr($element, '.time') !== false) {
  114. $string = "tracktime";
  115. } else if (stristr($element, '.correct_responses._count') !== false) {
  116. $string = "trackcorrectcount";
  117. } else if (stristr($element, '.score.min') !== false) {
  118. $string = "trackscoremin";
  119. } else if (stristr($element, '.score.max') !== false) {
  120. $string = "trackscoremax";
  121. } else if (stristr($element, '.score.raw') !== false) {
  122. $string = "trackscoreraw";
  123. } else if (stristr($element, '.latency') !== false) {
  124. $string = "tracklatency";
  125. } else if (stristr($element, '.pattern') !== false) {
  126. $string = "trackpattern";
  127. } else if (stristr($element, '.suspend_data') !== false) {
  128. $string = "tracksuspenddata";
  129. }
  130. if (empty($string) || $table->is_downloading()) {
  131. $row[] = $element;
  132. } else {
  133. $row[] = $element.$OUTPUT->help_icon($string, 'scorm');
  134. }
  135. if (strpos($element, '_time') === false) {
  136. $row[] = s($value);
  137. } else {
  138. $row[] = s(scorm_format_duration($value));
  139. }
  140. $table->add_data($row);
  141. }
  142. }
  143. $table->finish_output();
  144. if (!$table->is_downloading()) {
  145. echo $OUTPUT->box_end();
  146. echo $OUTPUT->footer();
  147. }