Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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 35 // Building the url to use for links.+ data details buildup. 36 $url = new moodle_url('/mod/scorm/report/userreportinteractions.php', array('id' => $id, 37 'user' => $userid, 38 'attempt' => $attempt)); 39 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 // Get list of attempts this user has made. 45 $attemptids = scorm_get_all_attempts($scorm->id, $userid); 46 47 $PAGE->set_url($url); 48 // END of url setting + data buildup. 49 50 // Checking login +logging +getting context. 51 require_login($course, false, $cm); 52 $contextmodule = context_module::instance($cm->id); 53 require_capability('mod/scorm:viewreport', $contextmodule); 54 55 // Check user has group access. 56 if (!groups_user_groups_visible($course, $userid, $cm)) { 57 throw new moodle_exception('nopermissiontoshow'); 58 } 59 60 // Trigger a user interactions viewed event. 61 $event = \mod_scorm\event\interactions_viewed::create(array( 62 'context' => $contextmodule, 63 'relateduserid' => $userid, 64 'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id) 65 )); 66 $event->add_record_snapshot('course_modules', $cm); 67 $event->add_record_snapshot('scorm', $scorm); 68 $event->trigger(); 69 70 $trackdata = $DB->get_records('scorm_scoes_track', array('userid' => $user->id, 'scormid' => $scorm->id, 71 'attempt' => $attempt)); 72 $usertrack = scorm_format_interactions($trackdata); 73 74 $questioncount = get_scorm_question_count($scorm->id); 75 76 $courseshortname = format_string($course->shortname, true, 77 array('context' => context_course::instance($course->id))); 78 $exportfilename = $courseshortname . '-' . format_string($scorm->name, true) . '-' . get_string('interactions', 'scorm'); 79 80 81 // Set up the table. 82 $table = new flexible_table('mod-scorm-userreport-interactions'); 83 if (!$table->is_downloading($download, $exportfilename)) { 84 85 // Print the page header. 86 $strattempt = get_string('attempt', 'scorm'); 87 $strreport = get_string('report', 'scorm'); 88 89 $PAGE->set_title("$course->shortname: ".format_string($scorm->name)); 90 $PAGE->set_heading($course->fullname); 91 $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id))); 92 93 $PAGE->navbar->add(fullname($user). " - $strattempt $attempt"); 94 95 echo $OUTPUT->header(); 96 echo $OUTPUT->heading(format_string($scorm->name)); 97 // End of Print the page header. 98 $currenttab = 'interactions'; 99 require($CFG->dirroot . '/mod/scorm/report/userreporttabs.php'); 100 101 // Printing user details. 102 $output = $PAGE->get_renderer('mod_scorm'); 103 echo $output->view_user_heading($user, $course, $PAGE->url, $attempt, $attemptids); 104 105 } 106 $table->define_baseurl($PAGE->url); 107 $table->define_columns(array('id', 'studentanswer', 'correctanswer', 'result', 'calcweight')); 108 $table->define_headers(array(get_string('trackid', 'scorm'), get_string('response', 'scorm'), 109 get_string('rightanswer', 'scorm'), get_string('result', 'scorm'), 110 get_string('calculatedweight', 'scorm'))); 111 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); 112 113 $table->show_download_buttons_at(array(TABLE_P_BOTTOM)); 114 $table->setup(); 115 116 for ($i = 0; $i < $questioncount; $i++) { 117 $row = array(); 118 $element = 'cmi.interactions_'.$i.'.id'; 119 if (isset($usertrack->$element)) { 120 $row[] = s($usertrack->$element); 121 122 $element = 'cmi.interactions_'.$i.'.student_response'; 123 if (isset($usertrack->$element)) { 124 $row[] = s($usertrack->$element); 125 } else { 126 $row[] = ' '; 127 } 128 129 $j = 0; 130 $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern'; 131 $rightans = ''; 132 if (isset($usertrack->$element)) { 133 while (isset($usertrack->$element)) { 134 if ($j > 0) { 135 $rightans .= ','; 136 } 137 $rightans .= s($usertrack->$element); 138 $j++; 139 $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern'; 140 } 141 $row[] = $rightans; 142 } else { 143 $row[] = ' '; 144 } 145 $element = 'cmi.interactions_'.$i.'.result'; 146 $weighting = 'cmi.interactions_'.$i.'.weighting'; 147 if (isset($usertrack->$element)) { 148 $row[] = s($usertrack->$element); 149 if ($usertrack->$element == 'correct' && 150 isset($usertrack->$weighting)) { 151 $row[] = s($usertrack->$weighting); 152 } else { 153 $row[] = '0'; 154 } 155 } else { 156 $row[] = ' '; 157 } 158 $table->add_data($row); 159 } 160 } 161 162 $table->finish_output(); 163 164 if (!$table->is_downloading()) { 165 echo $OUTPUT->footer(); 166 } 167
title
Description
Body
title
Description
Body
title
Description
Body
title
Body