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