Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/scorm/userreport.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
00016 
00026 require_once("../../config.php");
00027 require_once($CFG->dirroot.'/mod/scorm/locallib.php');
00028 
00029 $user = required_param('user', PARAM_INT); // User ID
00030 
00031 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
00032 $a = optional_param('a', '', PARAM_INT); // SCORM ID
00033 $b = optional_param('b', '', PARAM_INT); // SCO ID
00034 $attempt = optional_param('attempt', '1', PARAM_INT); // attempt number
00035 
00036 // Building the url to use for links.+ data details buildup
00037 $url = new moodle_url('/mod/scorm/userreport.php');
00038 $url->param('user', $user);
00039 
00040 if ($attempt !== '1') {
00041     $url->param('attempt', $attempt);
00042 }
00043 
00044 if (!empty($id)) {
00045     $url->param('id', $id);
00046     $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
00047     $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00048     $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
00049 } else {
00050     if (!empty($b)) {
00051         $url->param('b', $b);
00052         $selsco = $DB->get_record('scorm_scoes', array('id' => $b), '*', MUST_EXIST);
00053         $a = $selsco->scorm;
00054     }
00055     if (!empty($a)) {
00056         $url->param('a', $a);
00057         $scorm = $DB->get_record('scorm', array('id' => $a), '*', MUST_EXIST);
00058         $course = $DB->get_record('course', array('id' => $scorm->course), '*', MUST_EXIST);
00059         $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id, false, MUST_EXIST);
00060     }
00061 }
00062 $PAGE->set_url($url);
00063 //END of url setting + data buildup
00064 
00065 // checking login +logging +getting context
00066 require_login($course->id, false, $cm);
00067 $contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
00068 require_capability('mod/scorm:viewreport', $contextmodule);
00069 
00070 add_to_log($course->id, 'scorm', 'userreport', 'userreport.php?id='.$cm->id, $scorm->id, $cm->id);
00071 $userdata = scorm_get_user_data($user);
00072 
00073 // Print the page header
00074 $strreport = get_string('report', 'scorm');
00075 $strattempt = get_string('attempt', 'scorm');
00076 
00077 $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
00078 $PAGE->set_heading($course->fullname);
00079 $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id'=>$cm->id)));
00080 
00081 if (empty($b)) {
00082     if (!empty($a)) {
00083         $PAGE->navbar->add("$strattempt $attempt - ".fullname($userdata));
00084     }
00085 } else {
00086     $PAGE->navbar->add("$strattempt $attempt - ".fullname($userdata), new moodle_url('/mod/scorm/userreport.php', array('a'=>$a, 'user'=>$user, 'attempt'=>$attempt)));
00087     $PAGE->navbar->add($selsco->title);
00088 }
00089 echo $OUTPUT->header();
00090 echo $OUTPUT->heading(format_string($scorm->name));
00091 // End of Print the page header
00092 
00093 //Parameter Checking
00094 if (empty ($userdata)) {
00095     print_error('missingparameter');
00096 }
00097 
00098 //printing user details
00099 echo $OUTPUT->box_start('generalbox boxaligncenter');
00100 echo '<div class="mdl-align">'."\n";
00101 echo $OUTPUT->user_picture($userdata, array('courseid'=>$course->id));
00102 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&amp;course=$course->id\">".
00103     "$userdata->firstname $userdata->lastname</a><br />";
00104 echo get_string('attempt', 'scorm').': '.$attempt;
00105 echo '</div>'."\n";
00106 echo $OUTPUT->box_end();
00107 
00108 if ($scoes = $DB->get_records_select('scorm_scoes', "scorm=? ORDER BY id", array($scorm->id))) {
00109     // Print general score data
00110     $table = new html_table();
00111     $table->head = array(
00112             get_string('title', 'scorm'),
00113             get_string('status', 'scorm'),
00114             get_string('time', 'scorm'),
00115             get_string('score', 'scorm'),
00116             '');
00117     $table->align = array('left', 'center', 'center', 'right', 'left');
00118     $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
00119     $table->width = '80%';
00120     $table->size = array('*', '*', '*', '*', '*');
00121     foreach ($scoes as $sco) {
00122         if ($sco->launch!='') {
00123             $row = array();
00124             $score = '&nbsp;';
00125             if ($trackdata = scorm_get_tracks($sco->id, $user, $attempt)) {
00126                 if ($trackdata->score_raw != '') {
00127                     $score = $trackdata->score_raw;
00128                 }
00129                 if ($trackdata->status == '') {
00130                     $trackdata->status = 'notattempted';
00131                 }
00132                 $detailslink = '<a href="userreport.php?b='.$sco->id.'&amp;user='.$user.'&amp;attempt='.$attempt.'" title="'.
00133                 get_string('details', 'scorm').'">'.get_string('details', 'scorm').'</a>';
00134             } else {
00135                 $trackdata->status = 'notattempted';
00136                 $trackdata->total_time = '&nbsp;';
00137                 $detailslink = '&nbsp;';
00138             }
00139             $strstatus = get_string($trackdata->status, 'scorm');
00140             $row[] = '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.
00141             $strstatus.'" />&nbsp;'.format_string($sco->title);
00142             $row[] = get_string($trackdata->status, 'scorm');
00143             $row[] = scorm_format_duration($trackdata->total_time);
00144             $row[] = $score;
00145             $row[] = $detailslink;
00146         } else {
00147             $row = array(format_string($sco->title), '&nbsp;', '&nbsp;', '&nbsp;', '&nbsp;');
00148         }
00149         $table->data[] = $row;
00150     }
00151     echo html_writer::table($table);
00152 }
00153 
00154 if (!empty($b)) {
00155     echo $OUTPUT->box_start('generalbox boxaligncenter');
00156     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>');
00157     echo '<div class="mdl-align">'."\n";
00158     $scoreview = '';
00159     if ($trackdata = scorm_get_tracks($selsco->id, $user, $attempt)) {
00160         if ($trackdata->score_raw != '') {
00161             $scoreview = get_string('score', 'scorm').':&nbsp;'.$trackdata->score_raw;
00162         }
00163         if ($trackdata->status == '') {
00164             $trackdata->status = 'notattempted';
00165         }
00166     } else {
00167         $trackdata->status = 'notattempted';
00168         $trackdata->total_time = '';
00169     }
00170     $strstatus = get_string($trackdata->status, 'scorm');
00171     echo '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.
00172     $strstatus.'" />&nbsp;'.scorm_format_duration($trackdata->total_time).'<br />'.$scoreview.'<br />';
00173     echo '</div>'."\n";
00174     echo '<hr /><h2>'.get_string('details', 'scorm').'</h2>';
00175     // Print general score data
00176     $table = new html_table();
00177     $table->head = array(get_string('element', 'scorm'), get_string('value', 'scorm'));
00178     $table->align = array('left', 'left');
00179     $table->wrap = array('nowrap', 'nowrap');
00180     $table->width = '100%';
00181     $table->size = array('*', '*');
00182     $existelements = false;
00183     if (scorm_version_check($scorm->version, SCORM_13)) {
00184         $elements = array(
00185                 'raw' => 'cmi.score.raw',
00186                 'min' => 'cmi.score.min',
00187                 'max' => 'cmi.score.max',
00188                 'status' => 'cmi.completion_status',
00189                 'time' => 'cmi.total_time');
00190     } else {
00191         $elements = array(
00192                 'raw' => 'cmi.core.score.raw',
00193                 'min' => 'cmi.core.score.min',
00194                 'max' => 'cmi.core.score.max',
00195                 'status' => 'cmi.core.lesson_status',
00196                 'time' => 'cmi.core.total_time');
00197     }
00198     $printedelements = array();
00199     foreach ($elements as $key => $element) {
00200         if (isset($trackdata->$element)) {
00201             $existelements = true;
00202             $printedelements[]=$element;
00203             $row = array();
00204             $row[] = get_string($key, 'scorm');
00205             switch ($key) {
00206                 case 'status':
00207                     $row[] = $strstatus;
00208                 break;
00209                 case 'time':
00210                     $row[] = s(scorm_format_duration($trackdata->$element));
00211                 break;
00212                 default:
00213                     $row[] = s($trackdata->$element);
00214                 break;
00215             }
00216             $table->data[] = $row;
00217         }
00218     }
00219     if ($existelements) {
00220         echo '<h3>'.get_string('general', 'scorm').'</h3>';
00221         echo html_writer::table($table);
00222     }
00223     // Print Interactions data
00224     $table = new html_table();
00225     $table->head = array(
00226             get_string('identifier', 'scorm'),
00227             get_string('type', 'scorm'),
00228             get_string('result', 'scorm'),
00229             get_string('student_response', 'scorm'));
00230     $table->align = array('center', 'center', 'center', 'center');
00231     $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap');
00232     $table->width = '100%';
00233     $table->size = array('*', '*', '*', '*', '*');
00234     $existinteraction = false;
00235     $i = 0;
00236     $interactionid = 'cmi.interactions.'.$i.'.id';
00237 
00238     while (isset($trackdata->$interactionid)) {
00239         $existinteraction = true;
00240         $printedelements[]=$interactionid;
00241         $elements = array(
00242                 $interactionid,
00243                 'cmi.interactions.'.$i.'.type',
00244                 'cmi.interactions.'.$i.'.result',
00245                 'cmi.interactions.'.$i.'.learner_response');
00246         $row = array();
00247         foreach ($elements as $element) {
00248             if (isset($trackdata->$element)) {
00249                 $row[] = s($trackdata->$element);
00250                 $printedelements[]=$element;
00251             } else {
00252                 $row[] = '&nbsp;';
00253             }
00254         }
00255         $table->data[] = $row;
00256         $i++;
00257         $interactionid = 'cmi.interactions.'.$i.'.id';
00258     }
00259     if ($existinteraction) {
00260         echo '<h3>'.get_string('interactions', 'scorm').'</h3>';
00261         echo html_writer::table($table);
00262     }
00263 
00264     // Print Objectives data
00265     $table = new html_table();
00266     $table->head = array(
00267             get_string('identifier', 'scorm'),
00268             get_string('status', 'scorm'),
00269             get_string('raw', 'scorm'),
00270             get_string('min', 'scorm'),
00271             get_string('max', 'scorm'));
00272     $table->align = array('center', 'center', 'center', 'center', 'center');
00273     $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
00274     $table->width = '100%';
00275     $table->size = array('*', '*', '*', '*', '*');
00276     $existobjective = false;
00277 
00278     $i = 0;
00279     $objectiveid = 'cmi.objectives.'.$i.'.id';
00280 
00281     while (isset($trackdata->$objectiveid)) {
00282         $existobjective = true;
00283         $printedelements[]=$objectiveid;
00284         $elements = array(
00285                 $objectiveid,
00286                 'cmi.objectives.'.$i.'.status',
00287                 'cmi.objectives.'.$i.'.score.raw',
00288                 'cmi.objectives.'.$i.'.score.min',
00289                 'cmi.objectives.'.$i.'.score.max');
00290         $row = array();
00291         foreach ($elements as $element) {
00292             if (isset($trackdata->$element)) {
00293                 $row[] = s($trackdata->$element);
00294                 $printedelements[]=$element;
00295             } else {
00296                 $row[] = '&nbsp;';
00297             }
00298         }
00299         $table->data[] = $row;
00300 
00301         $i++;
00302         $objectiveid = 'cmi.objectives.'.$i.'.id';
00303     }
00304     if ($existobjective) {
00305         echo '<h3>'.get_string('objectives', 'scorm').'</h3>';
00306         echo html_writer::table($table);
00307     }
00308     $table = new html_table();
00309     $table->head = array(get_string('element', 'scorm'), get_string('elementdefinition', 'scorm'), get_string('value', 'scorm'));
00310     $table->align = array('left', 'left');
00311     $table->wrap = array('nowrap', 'wrap');
00312     $table->width = '100%';
00313     $table->size = array('*', '*');
00314 
00315     $existelements = false;
00316 
00317     foreach ($trackdata as $element => $value) {
00318         if (substr($element, 0, 3) == 'cmi') {
00319             if (!(in_array ($element, $printedelements))) {
00320                 $existelements = true;
00321                 $row = array();
00322                 $string=false;
00323                 if (stristr($element, '.id') !== false) {
00324                     $string="interactionsid";
00325                 } else if (stristr($element, '.result') !== false) {
00326                     $string="interactionsresult";
00327                 } else if (stristr($element, '.student_response') !== false) {
00328                     $string="interactionsresponse";
00329                 } else if (stristr($element, '.type') !== false) {
00330                     $string="interactionstype";
00331                 } else if (stristr($element, '.weighting') !== false) {
00332                     $string="interactionsweight";
00333                 } else if (stristr($element, '.time') !== false) {
00334                     $string="interactionstime";
00335                 } else if (stristr($element, '.correct_responses._count') !== false) {
00336                     $string="interactionscorrectcount";
00337                 } else if (stristr($element, '.learner_response') !== false) {
00338                     $string="interactionslearnerresponse";
00339                 } else if (stristr($element, '.score.min') !== false) {
00340                     $string="interactionsscoremin";
00341                 } else if (stristr($element, '.score.max') !== false) {
00342                     $string="interactionsscoremax";
00343                 } else if (stristr($element, '.score.raw') !== false) {
00344                     $string="interactionsscoreraw";
00345                 } else if (stristr($element, '.latency') !== false) {
00346                     $string="interactionslatency";
00347                 } else if (stristr($element, '.pattern') !== false) {
00348                     $string="interactionspattern";
00349                 } else if (stristr($element, '.suspend_data') !== false) {
00350                     $string="interactionssuspenddata";
00351                 }
00352                 $row[]=$element;
00353                 if (empty($string)) {
00354                     $row[]=null;
00355                 } else {
00356                     $row[] = get_string($string, 'scorm');
00357                 }
00358                 if (strpos($element, '_time') === false) {
00359                     $row[] = s($value);
00360                 } else {
00361                     $row[] = s(scorm_format_duration($value));
00362                 }
00363                 $table->data[] = $row;
00364             }
00365         }
00366     }
00367     if ($existelements) {
00368         echo '<h3>'.get_string('othertracks', 'scorm').'</h3>';
00369         echo html_writer::table($table);
00370     }
00371     echo $OUTPUT->box_end();
00372 }
00373 // Print footer
00374 
00375 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations