PageRenderTime 106ms CodeModel.GetById 21ms RepoModel.GetById 10ms app.codeStats 0ms

/mod/scorm/report/userreporttracks.php

https://github.com/mackensen/moodle
PHP | 172 lines | 128 code | 17 blank | 27 comment | 39 complexity | 38748eb99bd66922b2b6b986bba79f7b MD5 | raw file
  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. $mode = required_param('mode', PARAM_ALPHA); // Scorm mode.
  30. $attempt = optional_param('attempt', 1, PARAM_INT); // attempt number.
  31. $download = optional_param('download', '', PARAM_ALPHA);
  32. // Building the url to use for links.+ data details buildup.
  33. $url = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $id,
  34. 'user' => $userid,
  35. 'attempt' => $attempt,
  36. 'scoid' => $scoid,
  37. 'mode' => $mode));
  38. $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
  39. $course = get_course($cm->course);
  40. $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
  41. $user = $DB->get_record('user', array('id' => $userid), implode(',', \core_user\fields::get_picture_fields()), MUST_EXIST);
  42. $selsco = $DB->get_record('scorm_scoes', array('id' => $scoid), '*', MUST_EXIST);
  43. $PAGE->set_url($url);
  44. // END of url setting + data buildup.
  45. // Checking login +logging +getting context.
  46. require_login($course, false, $cm);
  47. $contextmodule = context_module::instance($cm->id);
  48. require_capability('mod/scorm:viewreport', $contextmodule);
  49. // Check user has group access.
  50. if (!groups_user_groups_visible($course, $userid, $cm)) {
  51. throw new moodle_exception('nopermissiontoshow');
  52. }
  53. // Trigger a tracks viewed event.
  54. $event = \mod_scorm\event\tracks_viewed::create(array(
  55. 'context' => $contextmodule,
  56. 'relateduserid' => $userid,
  57. 'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id, 'scoid' => $scoid, 'mode' => $mode)
  58. ));
  59. $event->add_record_snapshot('course_modules', $cm);
  60. $event->add_record_snapshot('scorm', $scorm);
  61. $event->trigger();
  62. // Print the page header.
  63. $strreport = get_string('report', 'scorm');
  64. $strattempt = get_string('attempt', 'scorm');
  65. $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
  66. $PAGE->set_heading($course->fullname);
  67. $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
  68. $PAGE->navbar->add("$strattempt $attempt - ".fullname($user),
  69. new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id, 'user' => $userid, 'attempt' => $attempt)));
  70. $PAGE->navbar->add($selsco->title . ' - '. get_string('details', 'scorm'));
  71. $PAGE->set_secondary_active_tab('scormreport');
  72. if ($trackdata = scorm_get_tracks($selsco->id, $userid, $attempt)) {
  73. if ($trackdata->status == '') {
  74. $trackdata->status = 'notattempted';
  75. }
  76. } else {
  77. $trackdata = new stdClass();
  78. $trackdata->status = 'notattempted';
  79. $trackdata->total_time = '';
  80. }
  81. $courseshortname = format_string($course->shortname, true,
  82. array('context' => context_course::instance($course->id)));
  83. $exportfilename = $courseshortname . '-' . format_string($scorm->name, true) . '-' . get_string('details', 'scorm');
  84. $table = new flexible_table('mod_scorm-userreporttracks');
  85. if (!$table->is_downloading($download, $exportfilename)) {
  86. $PAGE->activityheader->set_attrs([
  87. 'hidecompletion' => true,
  88. 'description' => ''
  89. ]);
  90. echo $OUTPUT->header();
  91. $currenttab = '';
  92. $renderer = $PAGE->get_renderer('mod_scorm');
  93. $useractionreport = new \mod_scorm\output\userreportsactionbar($id, $userid, $attempt, 'attempt', $mode, $scoid);
  94. echo $renderer->user_report_actionbar($useractionreport);
  95. echo $OUTPUT->box_start('generalbox boxaligncenter');
  96. echo $OUTPUT->heading("$strattempt $attempt - ". fullname($user).': '.
  97. format_string($selsco->title). ' - '. get_string('details', 'scorm'), 3);
  98. }
  99. $table->define_baseurl($PAGE->url);
  100. $table->define_columns(array('element', 'value'));
  101. $table->define_headers(array(get_string('element', 'scorm'), get_string('value', 'scorm')));
  102. $table->set_attribute('class', 'generaltable generalbox boxaligncenter scormtrackreport');
  103. $table->show_download_buttons_at(array(TABLE_P_BOTTOM));
  104. $table->setup();
  105. foreach ($trackdata as $element => $value) {
  106. if (substr($element, 0, 3) == 'cmi') {
  107. $existelements = true;
  108. $row = array();
  109. $string = false;
  110. if (stristr($element, '.id') !== false) {
  111. $string = "trackid";
  112. } else if (stristr($element, '.result') !== false) {
  113. $string = "trackresult";
  114. } else if (stristr($element, '.student_response') !== false or // SCORM 1.2 value.
  115. stristr($element, '.learner_response') !== false) { // SCORM 2004 value.
  116. $string = "trackresponse";
  117. } else if (stristr($element, '.type') !== false) {
  118. $string = "tracktype";
  119. } else if (stristr($element, '.weighting') !== false) {
  120. $string = "trackweight";
  121. } else if (stristr($element, '.time') !== false) {
  122. $string = "tracktime";
  123. } else if (stristr($element, '.correct_responses._count') !== false) {
  124. $string = "trackcorrectcount";
  125. } else if (stristr($element, '.score.min') !== false) {
  126. $string = "trackscoremin";
  127. } else if (stristr($element, '.score.max') !== false) {
  128. $string = "trackscoremax";
  129. } else if (stristr($element, '.score.raw') !== false) {
  130. $string = "trackscoreraw";
  131. } else if (stristr($element, '.latency') !== false) {
  132. $string = "tracklatency";
  133. } else if (stristr($element, '.pattern') !== false) {
  134. $string = "trackpattern";
  135. } else if (stristr($element, '.suspend_data') !== false) {
  136. $string = "tracksuspenddata";
  137. }
  138. if (empty($string) || $table->is_downloading()) {
  139. $row[] = $element;
  140. } else {
  141. $row[] = $element.$OUTPUT->help_icon($string, 'scorm');
  142. }
  143. if (strpos($element, '_time') === false) {
  144. $row[] = s($value);
  145. } else {
  146. $row[] = s(scorm_format_duration($value));
  147. }
  148. $table->add_data($row);
  149. }
  150. }
  151. $table->finish_output();
  152. if (!$table->is_downloading()) {
  153. echo $OUTPUT->box_end();
  154. echo $OUTPUT->footer();
  155. }