PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/mod/scorm/userreport.php

http://github.com/moodle/moodle
PHP | 375 lines | 317 code | 24 blank | 34 comment | 73 complexity | cd87e85685c433001fbfa0cd6567d284 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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
  20. * @subpackage 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. require_once("../../config.php");
  25. require_once($CFG->dirroot.'/mod/scorm/locallib.php');
  26. $user = required_param('user', PARAM_INT); // User ID
  27. $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
  28. $a = optional_param('a', '', PARAM_INT); // SCORM ID
  29. $b = optional_param('b', '', PARAM_INT); // SCO ID
  30. $attempt = optional_param('attempt', '1', PARAM_INT); // attempt number
  31. // Building the url to use for links.+ data details buildup
  32. $url = new moodle_url('/mod/scorm/userreport.php');
  33. $url->param('user', $user);
  34. if ($attempt !== '1') {
  35. $url->param('attempt', $attempt);
  36. }
  37. if (!empty($id)) {
  38. $url->param('id', $id);
  39. $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
  40. $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  41. $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
  42. } else {
  43. if (!empty($b)) {
  44. $url->param('b', $b);
  45. $selsco = $DB->get_record('scorm_scoes', array('id' => $b), '*', MUST_EXIST);
  46. $a = $selsco->scorm;
  47. }
  48. if (!empty($a)) {
  49. $url->param('a', $a);
  50. $scorm = $DB->get_record('scorm', array('id' => $a), '*', MUST_EXIST);
  51. $course = $DB->get_record('course', array('id' => $scorm->course), '*', MUST_EXIST);
  52. $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id, false, MUST_EXIST);
  53. }
  54. }
  55. $PAGE->set_url($url);
  56. //END of url setting + data buildup
  57. // checking login +logging +getting context
  58. require_login($course->id, false, $cm);
  59. $contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
  60. require_capability('mod/scorm:viewreport', $contextmodule);
  61. add_to_log($course->id, 'scorm', 'userreport', 'userreport.php?id='.$cm->id, $scorm->id, $cm->id);
  62. $userdata = scorm_get_user_data($user);
  63. // Print the page header
  64. $strreport = get_string('report', 'scorm');
  65. $strattempt = get_string('attempt', 'scorm');
  66. $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
  67. $PAGE->set_heading($course->fullname);
  68. $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id'=>$cm->id)));
  69. if (empty($b)) {
  70. if (!empty($a)) {
  71. $PAGE->navbar->add("$strattempt $attempt - ".fullname($userdata));
  72. }
  73. } else {
  74. $PAGE->navbar->add("$strattempt $attempt - ".fullname($userdata), new moodle_url('/mod/scorm/userreport.php', array('a'=>$a, 'user'=>$user, 'attempt'=>$attempt)));
  75. $PAGE->navbar->add($selsco->title);
  76. }
  77. echo $OUTPUT->header();
  78. echo $OUTPUT->heading(format_string($scorm->name));
  79. // End of Print the page header
  80. //Parameter Checking
  81. if (empty ($userdata)) {
  82. print_error('missingparameter');
  83. }
  84. //printing user details
  85. echo $OUTPUT->box_start('generalbox boxaligncenter');
  86. echo '<div class="mdl-align">'."\n";
  87. echo $OUTPUT->user_picture($userdata, array('courseid'=>$course->id));
  88. echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&amp;course=$course->id\">".
  89. "$userdata->firstname $userdata->lastname</a><br />";
  90. echo get_string('attempt', 'scorm').': '.$attempt;
  91. echo '</div>'."\n";
  92. echo $OUTPUT->box_end();
  93. if ($scoes = $DB->get_records_select('scorm_scoes', "scorm=? ORDER BY id", array($scorm->id))) {
  94. // Print general score data
  95. $table = new html_table();
  96. $table->head = array(
  97. get_string('title', 'scorm'),
  98. get_string('status', 'scorm'),
  99. get_string('time', 'scorm'),
  100. get_string('score', 'scorm'),
  101. '');
  102. $table->align = array('left', 'center', 'center', 'right', 'left');
  103. $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
  104. $table->width = '80%';
  105. $table->size = array('*', '*', '*', '*', '*');
  106. foreach ($scoes as $sco) {
  107. if ($sco->launch!='') {
  108. $row = array();
  109. $score = '&nbsp;';
  110. if ($trackdata = scorm_get_tracks($sco->id, $user, $attempt)) {
  111. if ($trackdata->score_raw != '') {
  112. $score = $trackdata->score_raw;
  113. }
  114. if ($trackdata->status == '') {
  115. $trackdata->status = 'notattempted';
  116. }
  117. $detailslink = '<a href="userreport.php?b='.$sco->id.'&amp;user='.$user.'&amp;attempt='.$attempt.'" title="'.
  118. get_string('details', 'scorm').'">'.get_string('details', 'scorm').'</a>';
  119. } else {
  120. $trackdata->status = 'notattempted';
  121. $trackdata->total_time = '&nbsp;';
  122. $detailslink = '&nbsp;';
  123. }
  124. $strstatus = get_string($trackdata->status, 'scorm');
  125. $row[] = '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.
  126. $strstatus.'" />&nbsp;'.format_string($sco->title);
  127. $row[] = get_string($trackdata->status, 'scorm');
  128. $row[] = scorm_format_duration($trackdata->total_time);
  129. $row[] = $score;
  130. $row[] = $detailslink;
  131. } else {
  132. $row = array(format_string($sco->title), '&nbsp;', '&nbsp;', '&nbsp;', '&nbsp;');
  133. }
  134. $table->data[] = $row;
  135. }
  136. echo html_writer::table($table);
  137. }
  138. if (!empty($b)) {
  139. echo $OUTPUT->box_start('generalbox boxaligncenter');
  140. echo $OUTPUT->heading('<a href="'.$CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;mode=browse&amp;scoid='.$selsco->id.'" target="_new">'.format_string($selsco->title).'</a>');
  141. echo '<div class="mdl-align">'."\n";
  142. $scoreview = '';
  143. if ($trackdata = scorm_get_tracks($selsco->id, $user, $attempt)) {
  144. if ($trackdata->score_raw != '') {
  145. $scoreview = get_string('score', 'scorm').':&nbsp;'.$trackdata->score_raw;
  146. }
  147. if ($trackdata->status == '') {
  148. $trackdata->status = 'notattempted';
  149. }
  150. } else {
  151. $trackdata->status = 'notattempted';
  152. $trackdata->total_time = '';
  153. }
  154. $strstatus = get_string($trackdata->status, 'scorm');
  155. echo '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.
  156. $strstatus.'" />&nbsp;'.scorm_format_duration($trackdata->total_time).'<br />'.$scoreview.'<br />';
  157. echo '</div>'."\n";
  158. echo '<hr /><h2>'.get_string('details', 'scorm').'</h2>';
  159. // Print general score data
  160. $table = new html_table();
  161. $table->head = array(get_string('element', 'scorm'), get_string('value', 'scorm'));
  162. $table->align = array('left', 'left');
  163. $table->wrap = array('nowrap', 'nowrap');
  164. $table->width = '100%';
  165. $table->size = array('*', '*');
  166. $existelements = false;
  167. if (scorm_version_check($scorm->version, SCORM_13)) {
  168. $elements = array(
  169. 'raw' => 'cmi.score.raw',
  170. 'min' => 'cmi.score.min',
  171. 'max' => 'cmi.score.max',
  172. 'status' => 'cmi.completion_status',
  173. 'time' => 'cmi.total_time');
  174. } else {
  175. $elements = array(
  176. 'raw' => 'cmi.core.score.raw',
  177. 'min' => 'cmi.core.score.min',
  178. 'max' => 'cmi.core.score.max',
  179. 'status' => 'cmi.core.lesson_status',
  180. 'time' => 'cmi.core.total_time');
  181. }
  182. $printedelements = array();
  183. foreach ($elements as $key => $element) {
  184. if (isset($trackdata->$element)) {
  185. $existelements = true;
  186. $printedelements[]=$element;
  187. $row = array();
  188. $row[] = get_string($key, 'scorm');
  189. switch ($key) {
  190. case 'status':
  191. $row[] = $strstatus;
  192. break;
  193. case 'time':
  194. $row[] = s(scorm_format_duration($trackdata->$element));
  195. break;
  196. default:
  197. $row[] = s($trackdata->$element);
  198. break;
  199. }
  200. $table->data[] = $row;
  201. }
  202. }
  203. if ($existelements) {
  204. echo '<h3>'.get_string('general', 'scorm').'</h3>';
  205. echo html_writer::table($table);
  206. }
  207. // Print Interactions data
  208. $table = new html_table();
  209. $table->head = array(
  210. get_string('identifier', 'scorm'),
  211. get_string('type', 'scorm'),
  212. get_string('result', 'scorm'),
  213. get_string('student_response', 'scorm'));
  214. $table->align = array('center', 'center', 'center', 'center');
  215. $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap');
  216. $table->width = '100%';
  217. $table->size = array('*', '*', '*', '*', '*');
  218. $existinteraction = false;
  219. $i = 0;
  220. $interactionid = 'cmi.interactions.'.$i.'.id';
  221. while (isset($trackdata->$interactionid)) {
  222. $existinteraction = true;
  223. $printedelements[]=$interactionid;
  224. $elements = array(
  225. $interactionid,
  226. 'cmi.interactions.'.$i.'.type',
  227. 'cmi.interactions.'.$i.'.result',
  228. 'cmi.interactions.'.$i.'.learner_response');
  229. $row = array();
  230. foreach ($elements as $element) {
  231. if (isset($trackdata->$element)) {
  232. $row[] = s($trackdata->$element);
  233. $printedelements[]=$element;
  234. } else {
  235. $row[] = '&nbsp;';
  236. }
  237. }
  238. $table->data[] = $row;
  239. $i++;
  240. $interactionid = 'cmi.interactions.'.$i.'.id';
  241. }
  242. if ($existinteraction) {
  243. echo '<h3>'.get_string('interactions', 'scorm').'</h3>';
  244. echo html_writer::table($table);
  245. }
  246. // Print Objectives data
  247. $table = new html_table();
  248. $table->head = array(
  249. get_string('identifier', 'scorm'),
  250. get_string('status', 'scorm'),
  251. get_string('raw', 'scorm'),
  252. get_string('min', 'scorm'),
  253. get_string('max', 'scorm'));
  254. $table->align = array('center', 'center', 'center', 'center', 'center');
  255. $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
  256. $table->width = '100%';
  257. $table->size = array('*', '*', '*', '*', '*');
  258. $existobjective = false;
  259. $i = 0;
  260. $objectiveid = 'cmi.objectives.'.$i.'.id';
  261. while (isset($trackdata->$objectiveid)) {
  262. $existobjective = true;
  263. $printedelements[]=$objectiveid;
  264. $elements = array(
  265. $objectiveid,
  266. 'cmi.objectives.'.$i.'.status',
  267. 'cmi.objectives.'.$i.'.score.raw',
  268. 'cmi.objectives.'.$i.'.score.min',
  269. 'cmi.objectives.'.$i.'.score.max');
  270. $row = array();
  271. foreach ($elements as $element) {
  272. if (isset($trackdata->$element)) {
  273. $row[] = s($trackdata->$element);
  274. $printedelements[]=$element;
  275. } else {
  276. $row[] = '&nbsp;';
  277. }
  278. }
  279. $table->data[] = $row;
  280. $i++;
  281. $objectiveid = 'cmi.objectives.'.$i.'.id';
  282. }
  283. if ($existobjective) {
  284. echo '<h3>'.get_string('objectives', 'scorm').'</h3>';
  285. echo html_writer::table($table);
  286. }
  287. $table = new html_table();
  288. $table->head = array(get_string('element', 'scorm'), get_string('elementdefinition', 'scorm'), get_string('value', 'scorm'));
  289. $table->align = array('left', 'left');
  290. $table->wrap = array('nowrap', 'wrap');
  291. $table->width = '100%';
  292. $table->size = array('*', '*');
  293. $existelements = false;
  294. foreach ($trackdata as $element => $value) {
  295. if (substr($element, 0, 3) == 'cmi') {
  296. if (!(in_array ($element, $printedelements))) {
  297. $existelements = true;
  298. $row = array();
  299. $string=false;
  300. if (stristr($element, '.id') !== false) {
  301. $string="interactionsid";
  302. } else if (stristr($element, '.result') !== false) {
  303. $string="interactionsresult";
  304. } else if (stristr($element, '.student_response') !== false) {
  305. $string="interactionsresponse";
  306. } else if (stristr($element, '.type') !== false) {
  307. $string="interactionstype";
  308. } else if (stristr($element, '.weighting') !== false) {
  309. $string="interactionsweight";
  310. } else if (stristr($element, '.time') !== false) {
  311. $string="interactionstime";
  312. } else if (stristr($element, '.correct_responses._count') !== false) {
  313. $string="interactionscorrectcount";
  314. } else if (stristr($element, '.learner_response') !== false) {
  315. $string="interactionslearnerresponse";
  316. } else if (stristr($element, '.score.min') !== false) {
  317. $string="interactionsscoremin";
  318. } else if (stristr($element, '.score.max') !== false) {
  319. $string="interactionsscoremax";
  320. } else if (stristr($element, '.score.raw') !== false) {
  321. $string="interactionsscoreraw";
  322. } else if (stristr($element, '.latency') !== false) {
  323. $string="interactionslatency";
  324. } else if (stristr($element, '.pattern') !== false) {
  325. $string="interactionspattern";
  326. } else if (stristr($element, '.suspend_data') !== false) {
  327. $string="interactionssuspenddata";
  328. }
  329. $row[]=$element;
  330. if (empty($string)) {
  331. $row[]=null;
  332. } else {
  333. $row[] = get_string($string, 'scorm');
  334. }
  335. if (strpos($element, '_time') === false) {
  336. $row[] = s($value);
  337. } else {
  338. $row[] = s(scorm_format_duration($value));
  339. }
  340. $table->data[] = $row;
  341. }
  342. }
  343. }
  344. if ($existelements) {
  345. echo '<h3>'.get_string('othertracks', 'scorm').'</h3>';
  346. echo html_writer::table($table);
  347. }
  348. echo $OUTPUT->box_end();
  349. }
  350. // Print footer
  351. echo $OUTPUT->footer();