Added multi-attemps support

This commit is contained in:
bobopinna 2006-09-01 10:17:01 +00:00
parent 20aeb4b8e3
commit 773534f4a2

View file

@ -9,6 +9,7 @@
$a = optional_param('a', '', PARAM_INT); // SCORM ID $a = optional_param('a', '', PARAM_INT); // SCORM ID
$b = optional_param('b', '', PARAM_INT); // SCO ID $b = optional_param('b', '', PARAM_INT); // SCO ID
$user = optional_param('user', '', PARAM_INT); // User ID $user = optional_param('user', '', PARAM_INT); // User ID
$attempt = optional_param('attempt', '1', PARAM_INT); // attempt number
if (!empty($id)) { if (!empty($id)) {
if (! $cm = get_coursemodule_from_id('scorm', $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"); 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 /// Print the page header
if (empty($noheader)) { if (empty($noheader)) {
if ($course->category) { if ($course->category) {
@ -59,8 +66,10 @@
$strscorms = get_string("modulenameplural", "scorm"); $strscorms = get_string("modulenameplural", "scorm");
$strscorm = get_string("modulename", "scorm"); $strscorm = get_string("modulename", "scorm");
$strreport = get_string("report", "scorm"); $strreport = get_string("report", "scorm");
$strattempt = get_string("attempt", "scorm");
$strname = get_string('name'); $strname = get_string('name');
if (empty($b)) { if (empty($b)) {
if (empty($a)) {
print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",
"$navigation <a href=\"index.php?id=$course->id\">$strscorms</a> "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>
-> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a> -> $strreport", -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a> -> $strreport",
@ -69,7 +78,14 @@
print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",
"$navigation <a href=\"index.php?id=$course->id\">$strscorms</a> "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>
-> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a> -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a>
-> <a href=\"report.php?id=$cm->id\">$strreport</a> -> $sco->title", -> <a href=\"report.php?id=$cm->id\">$strreport</a> -> $strattempt $attempt - ".fullname($userdata),
"", "", true);
}
} else {
print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",
"$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>
-> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a>
-> <a href=\"report.php?a=$a&user=$user&attempt=$attempt\">$strattempt $attempt - ".fullname($userdata)."</a> -> $sco->title",
"", "", true); "", "", true);
} }
print_heading(format_string($scorm->name)); print_heading(format_string($scorm->name));
@ -77,67 +93,113 @@
$scormpixdir = $CFG->modpixpath.'/scorm/pix'; $scormpixdir = $CFG->modpixpath.'/scorm/pix';
if (empty($b) ) { if (empty($b)) {
if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) { if (empty($a)) {
if ($scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid")) { if ($scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid")) {
$table = new stdClass(); $table = new stdClass();
$table->head = array('&nbsp;', $strname); $table->head = array('&nbsp;', get_string('name'));
$table->align = array('center', 'left'); $table->align = array('center', 'left');
$table->wrap = array('nowrap', 'nowrap'); $table->wrap = array('nowrap', 'nowrap');
$table->width = '100%'; $table->width = '100%';
$table->size = array(10, '*'); $table->size = array(10, '*');
foreach ($scoes as $sco) {
if ($sco->launch!='') { $table->head[]= get_string('attempt','scorm');
$table->head[]=scorm_string_wrap($sco->title);
//$table->head[]=$sco->title;
$table->align[] = 'center'; $table->align[] = 'center';
$table->wrap[] = 'nowrap'; $table->wrap[] = 'nowrap';
$table->size[] = '*'; $table->size[] = '*';
}
}
foreach ($scousers as $scouser) { $table->head[]= get_string('started','scorm');
if ($userdata = scorm_get_user_data($scouser->userid)) { $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 = array();
$row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true); $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true);
$row[] = "<a href=\"$CFG->wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">". $row[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$scouser->userid.'&course='.$course->id.'">'.
"$userdata->firstname $userdata->lastname</a>"; fullname($userdata).'</a>';
foreach ($scoes as $sco) { $row[] = '<a href="report.php?a='.$scorm->id.'&user='.$scouser->userid.'&attempt='.$a.'">'.$a.'</a>';
if ($sco->launch!='') { $select = 'scormid = '.$scorm->id.' and userid = '.$scouser->userid.' and attempt = '.$a;
$anchorstart = ''; $timetracks = get_record_select("scorm_scoes_track", $select,'min(timemodified) as started, max(timemodified) as last');
$anchorend = ''; $row[] = userdate($timetracks->started, get_string('strftimedaydatetime'));
$scoreview = ''; $row[] = userdate($timetracks->last, get_string('strftimedaydatetime'));
if ($trackdata = scorm_get_tracks($sco->id,$scouser->userid)) {
if ($trackdata->score_raw != '') {
$scoreview = '<br />'.get_string('score','scorm').':&nbsp;'.$trackdata->score_raw;
}
if ($trackdata->status == '') {
$trackdata->status = 'notattempted';
} else {
$anchorstart = '<a href="report.php?b='.$sco->id.'&user='.$scouser->userid.'" title="'.
get_string('details','scorm').'">';
$anchorend = '</a>';
}
} else {
$trackdata->status = 'notattempted';
$trackdata->total_time = '';
}
$strstatus = get_string($trackdata->status,'scorm');
$row[] = $anchorstart.'<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
$strstatus.'">&nbsp;'.$trackdata->total_time.$scoreview.$anchorend;
}
}
$table->data[] = $row; $table->data[] = $row;
} }
} }
}
print_table($table); 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 '<div align="center">'."\n";
print_user_picture($user, $course->id, $userdata->picture, false, false);
echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&course=$course->id\">".
"$userdata->firstname $userdata->lastname</a><br />";
echo get_string('attempt','scorm').': '.$attempt;
echo '</div>'."\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!='') {
$row = array();
if ($trackdata = scorm_get_tracks($sco->id,$user,$attempt)) {
if ($trackdata->score_raw != '') {
$score = $trackdata->score_raw;
} else {
$score = '&nbsp;';
}
if ($trackdata->status == '') {
$trackdata->status = 'notattempted';
}
$detailslink = '<a href="report.php?b='.$sco->id.'&user='.$user.'&attempt='.$attempt.'" title="'.
get_string('details','scorm').'">'.get_string('details','scorm').'</a>';
} else {
$trackdata->status = 'notattempted';
$trackdata->total_time = '&nbsp;';
$detailslink = '&nbsp;';
}
$row[] = '<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
$strstatus.'">&nbsp;'.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), '&nbsp;', '&nbsp;', '&nbsp;', '&nbsp;');
}
$table->data[] = $row;
}
print_table($table);
}
}
} else { } else {
notice('No users to report'); notice('No users to report');
} }
} }
} else { } else {
if (!empty($user)) { if (!empty($userdata)) {
if ($userdata = scorm_get_user_data($user)) {
print_simple_box_start('center'); print_simple_box_start('center');
print_heading(format_string($sco->title)); print_heading(format_string($sco->title));
echo '<div align="center">'."\n"; echo '<div align="center">'."\n";
@ -145,7 +207,7 @@
echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&course=$course->id\">". echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&course=$course->id\">".
"$userdata->firstname $userdata->lastname</a><br />"; "$userdata->firstname $userdata->lastname</a><br />";
$scoreview = ''; $scoreview = '';
if ($trackdata = scorm_get_tracks($sco->id,$user)) { if ($trackdata = scorm_get_tracks($sco->id,$user,$attempt)) {
if ($trackdata->score_raw != '') { if ($trackdata->score_raw != '') {
$scoreview = get_string('score','scorm').':&nbsp;'.$trackdata->score_raw; $scoreview = get_string('score','scorm').':&nbsp;'.$trackdata->score_raw;
} }
@ -309,59 +371,12 @@
print_table($table); print_table($table);
} }
print_simple_box_end(); print_simple_box_end();
}
} else { } else {
error('Missing script parameter'); 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('&nbsp;', 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[] = "<a href=\"$CFG->wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">".
"$userdata->firstname $userdata->lastname</a>";
$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 "<br><a href='viewScore.php?a=$scorm->id'>".format_string(get_string('viewscore','scorm'))."</a>";
if (empty($noheader)) { if (empty($noheader)) {
print_footer($course); print_footer($course);
} }