From 773534f4a22c55a843faabc18b03718701b1fd1e Mon Sep 17 00:00:00 2001 From: bobopinna Date: Fri, 1 Sep 2006 10:17:01 +0000 Subject: [PATCH] Added multi-attemps support --- mod/scorm/report.php | 495 ++++++++++++++++++++++--------------------- 1 file changed, 255 insertions(+), 240 deletions(-) diff --git a/mod/scorm/report.php b/mod/scorm/report.php index acf7686786..749a977d94 100755 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -9,6 +9,7 @@ $a = optional_param('a', '', PARAM_INT); // SCORM ID $b = optional_param('b', '', PARAM_INT); // SCO ID $user = optional_param('user', '', PARAM_INT); // User ID + $attempt = optional_param('attempt', '1', PARAM_INT); // attempt number if (!empty($id)) { if (! $cm = get_coursemodule_from_id('scorm', $id)) { @@ -48,6 +49,12 @@ add_to_log($course->id, "scorm", "report", "report.php?id=$cm->id", "$scorm->id"); + if (!empty($user)) { + $userdata = scorm_get_user_data($user); + } else { + $userdata = null; + } + /// Print the page header if (empty($noheader)) { if ($course->category) { @@ -59,17 +66,26 @@ $strscorms = get_string("modulenameplural", "scorm"); $strscorm = get_string("modulename", "scorm"); $strreport = get_string("report", "scorm"); + $strattempt = get_string("attempt", "scorm"); $strname = get_string('name'); if (empty($b)) { - print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", - "$navigation id\">$strscorms - -> id\">".format_string($scorm->name,true)." -> $strreport", - "", "", true); + if (empty($a)) { + print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", + "$navigation id\">$strscorms + -> id\">".format_string($scorm->name,true)." -> $strreport", + "", "", true); + } else { + print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", + "$navigation id\">$strscorms + -> id\">".format_string($scorm->name,true)." + -> id\">$strreport -> $strattempt $attempt - ".fullname($userdata), + "", "", true); + } } else { print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", "$navigation id\">$strscorms -> id\">".format_string($scorm->name,true)." - -> id\">$strreport -> $sco->title", + -> $strattempt $attempt - ".fullname($userdata)." -> $sco->title", "", "", true); } print_heading(format_string($scorm->name)); @@ -77,291 +93,290 @@ $scormpixdir = $CFG->modpixpath.'/scorm/pix'; - if (empty($b) ) { - if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) { + if (empty($b)) { + if (empty($a)) { if ($scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid")) { $table = new stdClass(); - $table->head = array(' ', $strname); + $table->head = array(' ', get_string('name')); $table->align = array('center', 'left'); $table->wrap = array('nowrap', 'nowrap'); $table->width = '100%'; $table->size = array(10, '*'); - foreach ($scoes as $sco) { - if ($sco->launch!='') { - $table->head[]=scorm_string_wrap($sco->title); - //$table->head[]=$sco->title; - $table->align[] = 'center'; - $table->wrap[] = 'nowrap'; - $table->size[] = '*'; - } - } - foreach ($scousers as $scouser) { - if ($userdata = scorm_get_user_data($scouser->userid)) { + $table->head[]= get_string('attempt','scorm'); + $table->align[] = 'center'; + $table->wrap[] = 'nowrap'; + $table->size[] = '*'; + + $table->head[]= get_string('started','scorm'); + $table->align[] = 'center'; + $table->wrap[] = 'nowrap'; + $table->size[] = '*'; + + $table->head[]= get_string('last','scorm'); + $table->align[] = 'center'; + $table->wrap[] = 'nowrap'; + $table->size[] = '*'; + + foreach($scousers as $scouser){ + $userdata = scorm_get_user_data($scouser->userid); + $attempt = scorm_get_last_attempt($scorm->id,$scouser->userid); + for ($a = 1; $a<=$attempt; $a++) { $row = array(); $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true); - $row[] = "wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">". - "$userdata->firstname $userdata->lastname"; + $row[] = ''. + fullname($userdata).''; + $row[] = ''.$a.''; + $select = 'scormid = '.$scorm->id.' and userid = '.$scouser->userid.' and attempt = '.$a; + $timetracks = get_record_select("scorm_scoes_track", $select,'min(timemodified) as started, max(timemodified) as last'); + $row[] = userdate($timetracks->started, get_string('strftimedaydatetime')); + $row[] = userdate($timetracks->last, get_string('strftimedaydatetime')); + $table->data[] = $row; + } + } + } + print_table($table); + } else { + if (!empty($user)) { + if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) { + if (!empty($userdata)) { + print_simple_box_start('center'); + print_heading(format_string($sco->title)); + echo '
'."\n"; + print_user_picture($user, $course->id, $userdata->picture, false, false); + echo "wwwroot/user/view.php?id=$user&course=$course->id\">". + "$userdata->firstname $userdata->lastname
"; + echo get_string('attempt','scorm').': '.$attempt; + echo '
'."\n"; + print_simple_box_end(); + + // Print general score data + $table = new stdClass(); + $table->head = array(get_string('title','scorm'), + get_string('status','scorm'), + get_string('time','scorm'), + get_string('score','scorm'), + ''); + $table->align = array('left', 'center','center','right','left'); + $table->wrap = array('nowrap', 'nowrap','nowrap','nowrap','nowrap'); + $table->width = '80%'; + $table->size = array('*', '*', '*', '*', '*'); foreach ($scoes as $sco) { if ($sco->launch!='') { - $anchorstart = ''; - $anchorend = ''; - $scoreview = ''; - if ($trackdata = scorm_get_tracks($sco->id,$scouser->userid)) { + $row = array(); + if ($trackdata = scorm_get_tracks($sco->id,$user,$attempt)) { if ($trackdata->score_raw != '') { - $scoreview = '
'.get_string('score','scorm').': '.$trackdata->score_raw; + $score = $trackdata->score_raw; + } else { + $score = ' '; } if ($trackdata->status == '') { $trackdata->status = 'notattempted'; - } else { - $anchorstart = ''; - $anchorend = ''; } + $detailslink = ''.get_string('details','scorm').''; } else { $trackdata->status = 'notattempted'; - $trackdata->total_time = ''; + $trackdata->total_time = ' '; + $detailslink = ' '; } - $strstatus = get_string($trackdata->status,'scorm'); - $row[] = $anchorstart.''.$strstatus.' '.$trackdata->total_time.$scoreview.$anchorend; + $row[] = ''.$strstatus.' '.format_string($sco->title); + $row[] = get_string($trackdata->status,'scorm'); + $row[] = $trackdata->total_time; + $row[] = $score; + $row[] = $detailslink; + } else { + $row = array(format_string($sco->title), ' ', ' ', ' ', ' '); } + $table->data[] = $row; } - $table->data[] = $row; + print_table($table); } } - print_table($table); } else { notice('No users to report'); } } } else { - if (!empty($user)) { - if ($userdata = scorm_get_user_data($user)) { - print_simple_box_start('center'); - print_heading(format_string($sco->title)); - echo '
'."\n"; - print_user_picture($user, $course->id, $userdata->picture, false, false); - echo "wwwroot/user/view.php?id=$user&course=$course->id\">". - "$userdata->firstname $userdata->lastname
"; - $scoreview = ''; - if ($trackdata = scorm_get_tracks($sco->id,$user)) { - if ($trackdata->score_raw != '') { - $scoreview = get_string('score','scorm').': '.$trackdata->score_raw; - } - if ($trackdata->status == '') { - $trackdata->status = 'notattempted'; - } - } else { + if (!empty($userdata)) { + print_simple_box_start('center'); + print_heading(format_string($sco->title)); + echo '
'."\n"; + print_user_picture($user, $course->id, $userdata->picture, false, false); + echo "wwwroot/user/view.php?id=$user&course=$course->id\">". + "$userdata->firstname $userdata->lastname
"; + $scoreview = ''; + if ($trackdata = scorm_get_tracks($sco->id,$user,$attempt)) { + if ($trackdata->score_raw != '') { + $scoreview = get_string('score','scorm').': '.$trackdata->score_raw; + } + if ($trackdata->status == '') { $trackdata->status = 'notattempted'; - $trackdata->total_time = ''; } - $strstatus = get_string($trackdata->status,'scorm'); - echo ''.$strstatus.' '.$trackdata->total_time.'
'.$scoreview.'
'; - echo '
'."\n"; - echo '

'.get_string('details','scorm').'

'; - - // Print general score data - $table = new stdClass(); - $table->head = array(get_string('element','scorm'), get_string('value','scorm')); - $table->align = array('left', 'left'); - $table->wrap = array('nowrap', 'nowrap'); - $table->width = '100%'; - $table->size = array('*', '*'); - - $existelements = false; - if ($scorm->version == 'SCORM_1.3') { - $elements = array('raw' => 'cmi.score.raw', - 'min' => 'cmi.score.min', - 'max' => 'cmi.score.max', - 'status' => 'cmi.completition_status', - 'time' => 'cmi.total_time'); - } else { - $elements = array('raw' => 'cmi.core.score.raw', - 'min' => 'cmi.core.score.min', - 'max' => 'cmi.core.score.max', - 'status' => 'cmi.core.lesson_status', - 'time' => 'cmi.core.total_time'); + } else { + $trackdata->status = 'notattempted'; + $trackdata->total_time = ''; + } + $strstatus = get_string($trackdata->status,'scorm'); + echo ''.$strstatus.' '.$trackdata->total_time.'
'.$scoreview.'
'; + echo '
'."\n"; + echo '

'.get_string('details','scorm').'

'; + + // Print general score data + $table = new stdClass(); + $table->head = array(get_string('element','scorm'), get_string('value','scorm')); + $table->align = array('left', 'left'); + $table->wrap = array('nowrap', 'nowrap'); + $table->width = '100%'; + $table->size = array('*', '*'); + + $existelements = false; + if ($scorm->version == 'SCORM_1.3') { + $elements = array('raw' => 'cmi.score.raw', + 'min' => 'cmi.score.min', + 'max' => 'cmi.score.max', + 'status' => 'cmi.completition_status', + 'time' => 'cmi.total_time'); + } else { + $elements = array('raw' => 'cmi.core.score.raw', + 'min' => 'cmi.core.score.min', + 'max' => 'cmi.core.score.max', + 'status' => 'cmi.core.lesson_status', + 'time' => 'cmi.core.total_time'); + } + foreach ($elements as $key => $element) { + if (isset($trackdata->$element)) { + $existelements = true; + $printedelements[]=$element; + $row = array(); + $row[] = get_string($key,'scorm'); + $row[] = $trackdata->$element; + $table->data[] = $row; } - foreach ($elements as $key => $element) { + } + if ($existelements) { + echo '

'.get_string('general','scorm').'

'; + print_table($table); + } + + // Print Interactions data + $table = new stdClass(); + $table->head = array(get_string('identifier','scorm'), + get_string('type','scorm'), + get_string('result','scorm'), + get_string('student_response','scorm')); + $table->align = array('center', 'center', 'center', 'center'); + $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap'); + $table->width = '100%'; + $table->size = array('*', '*', '*', '*', '*'); + + $existinteraction = false; + + $i = 0; + $interactionid = 'cmi.interactions.'.$i.'.id'; + + while (isset($trackdata->$interactionid)) { + $existinteraction = true; + $printedelements[]=$interactionid; + $elements = array($interactionid, + 'cmi.interactions.'.$i.'.type', + 'cmi.interactions.'.$i.'.result', + 'cmi.interactions.'.$i.'.student_response'); + $row = array(); + foreach ($elements as $element) { if (isset($trackdata->$element)) { - $existelements = true; - $printedelements[]=$element; - $row = array(); - $row[] = get_string($key,'scorm'); $row[] = $trackdata->$element; - $table->data[] = $row; + $printedelements[]=$element; + } else { + $row[] = ' '; } } - if ($existelements) { - echo '

'.get_string('general','scorm').'

'; - print_table($table); - } - - // Print Interactions data - $table = new stdClass(); - $table->head = array(get_string('identifier','scorm'), - get_string('type','scorm'), - get_string('result','scorm'), - get_string('student_response','scorm')); - $table->align = array('center', 'center', 'center', 'center'); - $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap'); - $table->width = '100%'; - $table->size = array('*', '*', '*', '*', '*'); - - $existinteraction = false; + $table->data[] = $row; - $i = 0; + $i++; $interactionid = 'cmi.interactions.'.$i.'.id'; - - while (isset($trackdata->$interactionid)) { - $existinteraction = true; - $printedelements[]=$interactionid; - $elements = array($interactionid, - 'cmi.interactions.'.$i.'.type', - 'cmi.interactions.'.$i.'.result', - 'cmi.interactions.'.$i.'.student_response'); - $row = array(); - foreach ($elements as $element) { - if (isset($trackdata->$element)) { - $row[] = $trackdata->$element; - $printedelements[]=$element; - } else { - $row[] = ' '; - } + } + if ($existinteraction) { + echo '

'.get_string('interactions','scorm').'

'; + print_table($table); + } + + // Print Objectives data + $table = new stdClass(); + $table->head = array(get_string('identifier','scorm'), + get_string('status','scorm'), + get_string('raw','scorm'), + get_string('min','scorm'), + get_string('max','scorm')); + $table->align = array('center', 'center', 'center', 'center', 'center'); + $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap'); + $table->width = '100%'; + $table->size = array('*', '*', '*', '*', '*'); + + $existobjective = false; + + $i = 0; + $objectiveid = 'cmi.objectives.'.$i.'.id'; + + while (isset($trackdata->$objectiveid)) { + $existobjective = true; + $printedelements[]=$objectiveid; + $elements = array($objectiveid, + 'cmi.objectives.'.$i.'.status', + 'cmi.objectives.'.$i.'.score.raw', + 'cmi.objectives.'.$i.'.score.min', + 'cmi.objectives.'.$i.'.score.max'); + $row = array(); + foreach ($elements as $element) { + if (isset($trackdata->$element)) { + $row[] = $trackdata->$element; + $printedelements[]=$element; + } else { + $row[] = ' '; } - $table->data[] = $row; - - $i++; - $interactionid = 'cmi.interactions.'.$i.'.id'; - } - if ($existinteraction) { - echo '

'.get_string('interactions','scorm').'

'; - print_table($table); } + $table->data[] = $row; - // Print Objectives data - $table = new stdClass(); - $table->head = array(get_string('identifier','scorm'), - get_string('status','scorm'), - get_string('raw','scorm'), - get_string('min','scorm'), - get_string('max','scorm')); - $table->align = array('center', 'center', 'center', 'center', 'center'); - $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap'); - $table->width = '100%'; - $table->size = array('*', '*', '*', '*', '*'); - - $existobjective = false; - - $i = 0; + $i++; $objectiveid = 'cmi.objectives.'.$i.'.id'; - - while (isset($trackdata->$objectiveid)) { - $existobjective = true; - $printedelements[]=$objectiveid; - $elements = array($objectiveid, - 'cmi.objectives.'.$i.'.status', - 'cmi.objectives.'.$i.'.score.raw', - 'cmi.objectives.'.$i.'.score.min', - 'cmi.objectives.'.$i.'.score.max'); - $row = array(); - foreach ($elements as $element) { - if (isset($trackdata->$element)) { - $row[] = $trackdata->$element; - $printedelements[]=$element; - } else { - $row[] = ' '; - } - } - $table->data[] = $row; - - $i++; - $objectiveid = 'cmi.objectives.'.$i.'.id'; - } - if ($existobjective) { - echo '

'.get_string('objectives','scorm').'

'; - print_table($table); - } - $table = new stdClass(); - $table->head = array(get_string('element','scorm'), get_string('value','scorm')); - $table->align = array('left', 'left'); - $table->wrap = array('nowrap', 'wrap'); - $table->width = '100%'; - $table->size = array('*', '*'); - - $existelements = false; - - foreach($trackdata as $element => $value) { - if (substr($element,0,3) == 'cmi') { - if (!(in_array ($element, $printedelements))) { - $existelements = true; - $row = array(); - $row[] = get_string($element,'scorm') != '[['.$element.']]' ? get_string($element,'scorm') : $element; - $row[] = $value; - $table->data[] = $row; - } + } + if ($existobjective) { + echo '

'.get_string('objectives','scorm').'

'; + print_table($table); + } + $table = new stdClass(); + $table->head = array(get_string('element','scorm'), get_string('value','scorm')); + $table->align = array('left', 'left'); + $table->wrap = array('nowrap', 'wrap'); + $table->width = '100%'; + $table->size = array('*', '*'); + + $existelements = false; + + foreach($trackdata as $element => $value) { + if (substr($element,0,3) == 'cmi') { + if (!(in_array ($element, $printedelements))) { + $existelements = true; + $row = array(); + $row[] = get_string($element,'scorm') != '[['.$element.']]' ? get_string($element,'scorm') : $element; + $row[] = $value; + $table->data[] = $row; } } - if ($existelements) { - echo '

'.get_string('othertracks','scorm').'

'; - print_table($table); - } - print_simple_box_end(); } + if ($existelements) { + echo '

'.get_string('othertracks','scorm').'

'; + print_table($table); + } + print_simple_box_end(); } else { error('Missing script parameter'); } } - print_heading(format_string(get_string('timestatistic','scorm'))); - $scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid"); - $attempt = scorm_get_last_attempt($scorm->id,$USER->id); - - foreach($scousers as $scouser){ - $str = 'scormid ='.($scorm->id).' and userid = '.$scouser->userid.' and attempt = '.$attempt.' ORDER BY timemodified asc'; - $endtrack = get_record_select("scorm_scoes_track", $str,'max(timemodified) as maxtimemodified'); - - } - -//Phan trinh bay thong ke theo thoi gian - $table = new stdClass(); - $table->head = array(' ', get_string('name','scorm')); - $table->align = array('center', 'left'); - $table->wrap = array('nowrap', 'nowrap'); - $table->width = '100%'; - $table->size = array(10, '*'); - - $table->head[]=scorm_string_wrap(get_string('beginTime','scorm')); - $table->align[] = 'center'; - $table->wrap[] = 'nowrap'; - $table->size[] = '*'; - - $table->head[]=scorm_string_wrap(get_string('endTime','scorm')); - $table->align[] = 'center'; - $table->wrap[] = 'nowrap'; - $table->size[] = '*'; - - $row = array(); - $row[] = ""; - $row[] = "(".get_string('coefficient','scorm').")"; - foreach($scousers as $scouser){ - $userdata = scorm_get_user_data($scouser->userid); - $row = array(); - $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true); - $row[] = "wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">". - "$userdata->firstname $userdata->lastname"; - $str = 'scormid ='.($scorm->id).' and userid = '.$scouser->userid.' and attempt = '.$attempt.' ORDER BY timemodified asc'; - $begintrack = get_record_select("scorm_scoes_track", $str,'min(timemodified) as mintimemodified'); - $row[] = strftime( "%H h -%M ' - %S s - %d -%m-%Y", $begintrack->mintimemodified); - $endtrack = get_record_select("scorm_scoes_track", $str,'max(timemodified) as maxtimemodified'); - $row[] = strftime( "%H h -%M ' - %S s - %d -%m-%Y", $endtrack->maxtimemodified); - $table->data[] = $row; - } - print_table($table); - echo "
".format_string(get_string('viewscore','scorm')).""; if (empty($noheader)) { print_footer($course); } -- 2.39.5