Fixed some problems with reporting and multiattempts

This commit is contained in:
bobopinna 2006-09-26 07:56:07 +00:00
parent 8e00b731e1
commit a30b6819fc
5 changed files with 225 additions and 191 deletions

View File

@ -65,19 +65,19 @@
if (has_capability('mod/scorm:viewreport', $context)) {
$trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c');
if ($trackedusers->c > 0) {
$reportshow = '<a href="report.php?a='.$scorm->id.'">'.get_string('viewallreports','scorm',$trackedusers->c).'</a></div>';
$reportshow = '<a href="report.php?id='.$scorm->coursemodule.'">'.get_string('viewallreports','scorm',$trackedusers->c).'</a></div>';
} else {
$reportshow = get_string('noreports','scorm');
}
} else if (has_capability('mod/scorm:viewscores', $context)) {
require_once('locallib.php');
$report = scorm_grade_user(get_records('scorm_scoes','scorm',$scorm->id), $USER->id, $scorm->grademethod);
$report = scorm_grade_user($scorm, $USER->id);
$reportshow = get_string('score','scorm').": ".$report;
}
if (!$scorm->visible) {
//Show dimmed if the mod is hidden
$table->data[] = array ($tt, "<a class=\"dimmed\" href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name,true)."</a>",
format_text($scorm->summary),$reportshow);
format_text($scorm->summary), $reportshow);
} else {
//Show normal if the mod is visible
$table->data[] = array ($tt, "<a href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name,true)."</a>",
@ -92,4 +92,3 @@
print_footer($course);
?>

View File

@ -23,6 +23,7 @@ function scorm_add_instance($scorm) {
//sanitize submitted values a bit
$scorm->width = clean_param($scorm->width, PARAM_INT);
$scorm->height = clean_param($scorm->height, PARAM_INT);
$scorm->grademethod = ($scorm->whatgrade * 10) + $scorm->grademethod;
$id = insert_record('scorm', $scorm);
@ -63,6 +64,8 @@ function scorm_update_instance($scorm) {
$scorm->width = str_replace('%','',$scorm->width);
$scorm->height = str_replace('%','',$scorm->height);
$scorm->grademethod = ($scorm->whatgrade * 10) + $scorm->grademethod;
// Check if scorm manifest needs to be reparsed
if ($scorm->parse == 1) {
require_once('locallib.php');
@ -74,6 +77,7 @@ function scorm_update_instance($scorm) {
(basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')) {
rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id);
}
/* delete_records('scorm_sequencing_controlmode','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprules','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprule','scormid',$scorm->id);
@ -122,6 +126,7 @@ function scorm_delete_instance($id) {
if (! delete_records('scorm', 'id', $scorm->id)) {
$result = false;
}
/*if (! delete_records('scorm_sequencing_controlmode', 'scormid', $scorm->id)) {
$result = false;
}
@ -160,84 +165,11 @@ function scorm_delete_instance($id) {
function scorm_user_outline($course, $user, $mod, $scorm) {
$return = NULL;
$scores->values = 0;
$scores->sum = 0;
$scores->max = 0;
$scores->lastmodify = 0;
$scores->count = 0;
if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) {
require_once('locallib.php');
foreach ($scoes as $sco) {
if ($sco->launch!='') {
$scores->count++;
if ($userdata = scorm_get_tracks($sco->id, $user->id)) {
if (!isset($scores->{$userdata->status})) {
$scores->{$userdata->status} = 1;
} else {
$scores->{$userdata->status}++;
}
if (!empty($userdata->score_raw)) {
$scores->values++;
$scores->sum += $userdata->score_raw;
$scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
}
if (isset($userdata->timemodified) && ($userdata->timemodified > $scores->lastmodify)) {
$scores->lastmodify = $userdata->timemodified;
}
}
}
}
switch ($scorm->grademethod) {
case GRADEHIGHEST:
if ($scores->values > 0) {
$return->info = get_string('score','scorm').':&nbsp;'.$scores->max;
$return->time = $scores->lastmodify;
}
break;
case GRADEAVERAGE:
if ($scores->values > 0) {
$return->info = get_string('score','scorm').':&nbsp;'.$scores->sum/$scores->values;
$return->time = $scores->lastmodify;
}
break;
case GRADESUM:
if ($scores->values > 0) {
$return->info = get_string('score','scorm').':&nbsp;'.$scores->sum;
$return->time = $scores->lastmodify;
}
break;
case GRADESCOES:
$return->info = '';
$scores->notattempted = $scores->count;
if (isset($scores->completed)) {
$return->info .= get_string('completed','scorm').':&nbsp;'.$scores->completed.'<br />';
$scores->notattempted -= $scores->completed;
}
if (isset($scores->passed)) {
$return->info .= get_string('passed','scorm').':&nbsp;'.$scores->passed.'<br />';
$scores->notattempted -= $scores->passed;
}
if (isset($scores->failed)) {
$return->info .= get_string('failed','scorm').':&nbsp;'.$scores->failed.'<br />';
$scores->notattempted -= $scores->failed;
}
if (isset($scores->incomplete)) {
$return->info .= get_string('incomplete','scorm').':&nbsp;'.$scores->incomplete.'<br />';
$scores->notattempted -= $scores->incomplete;
}
if (isset($scores->browsed)) {
$return->info .= get_string('browsed','scorm').':&nbsp;'.$scores->browsed.'<br />';
$scores->notattempted -= $scores->browsed;
}
$return->time = $scores->lastmodify;
if ($return->info == '') {
$return = NULL;
} else {
$return->info .= get_string('notattempted','scorm').':&nbsp;'.$scores->notattempted.'<br />';
}
break;
}
}
require_once('locallib.php');
$return = scorm_grade_user($scorm, $user->id, true);
return $return;
}
@ -418,11 +350,8 @@ function scorm_grades($scormid) {
if (!$scorm = get_record('scorm', 'id', $scormid)) {
return NULL;
}
if (!$scoes = get_records('scorm_scoes','scorm',$scormid)) {
return NULL;
}
if ($scorm->grademethod == GRADESCOES) {
if (($scorm->grademethod % 10) == 0) { // GRADESCOES
if (!$return->maxgrade = count_records_select('scorm_scoes',"scorm='$scormid' AND launch<>''")) {
return NULL;
}
@ -434,7 +363,7 @@ function scorm_grades($scormid) {
if ($scousers=get_records_select('scorm_scoes_track', "scormid='$scormid' GROUP BY userid", "", "userid,null")) {
require_once('locallib.php');
foreach ($scousers as $scouser) {
$return->grades[$scouser->userid] = scorm_grade_user($scoes, $scouser->userid, $scorm->grademethod);
$return->grades[$scouser->userid] = scorm_grade_user($scorm, $scouser->userid);
}
}
return $return;

View File

@ -1,5 +1,66 @@
<?php // $Id$
/// Constants and settings for module scorm
define('GRADESCOES', '0');
define('GRADEHIGHEST', '1');
define('GRADEAVERAGE', '2');
define('GRADESUM', '3');
$SCORM_GRADE_METHOD = array (GRADESCOES => get_string('gradescoes', 'scorm'),
GRADEHIGHEST => get_string('gradehighest', 'scorm'),
GRADEAVERAGE => get_string('gradeaverage', 'scorm'),
GRADESUM => get_string('gradesum', 'scorm'));
define('HIGHESTATTEMPT', '0');
define('AVERAGEATTEMPT', '1');
define('FIRSTATTEMPT', '2');
define('LASTATTEMPT', '3');
$SCORM_WHAT_GRADE = array (HIGHESTATTEMPT => get_string('highestattempt', 'scorm'),
AVERAGEATTEMPT => get_string('averageattempt', 'scorm'),
FIRSTATTEMPT => get_string('firstattempt', 'scorm'),
LASTATTEMPT => get_string('lastattempt', 'scorm'));
$SCORM_POPUP_OPTIONS = array('resizable'=>1,
'scrollbars'=>1,
'directories'=>0,
'location'=>0,
'menubar'=>0,
'toolbar'=>0,
'status'=>0);
$stdoptions = '';
foreach ($SCORM_POPUP_OPTIONS as $popupopt => $value) {
$stdoptions .= $popupopt.'='.$value;
if ($popupopt != 'status') {
$stdoptions .= ',';
}
}
if (!isset($CFG->scorm_maxattempts)) {
set_config('scorm_maxattempts','6');
}
if (!isset($CFG->scorm_frameheight)) {
set_config('scorm_frameheight','500');
}
if (!isset($CFG->scorm_framewidth)) {
set_config('scorm_framewidth','100%');
}
if (!isset($CFG->scorm_advancedsettings)) {
set_config('scorm_advancedsettings','0');
}
if (!isset($CFG->scorm_windowsettings)) {
set_config('scorm_windowsettings','0');
}
//
// Repository configurations
//
$repositoryconfigfile = $CFG->dirroot.'/mod/resource/type/ims/repository_config.php';
$repositorybrowser = '/mod/resource/type/ims/finder.php';
/// Local Library of functions for module scorm
/**
@ -126,30 +187,6 @@ function scorm_external_link($link) {
return $result;
}
function scorm_string_wrap($stringa, $len=15) {
// Crop the given string into max $len characters lines
$textlib = textlib_get_instance();
if ($textlib->strlen($stringa, current_charset()) > $len) {
$words = explode(' ', $stringa);
$newstring = '';
$substring = '';
foreach ($words as $word) {
if (($textlib->strlen($substring, current_charset())+$textlib->strlen($word, current_charset())+1) < $len) {
$substring .= ' '.$word;
} else {
$newstring .= ' '.$substring.'<br />';
$substring = $word;
}
}
if (!empty($substring)) {
$newstring .= ' '.$substring;
}
return $newstring;
} else {
return $stringa;
}
}
/**
* Given a package directory, this function will check if the package is valid
*
@ -215,39 +252,16 @@ function scorm_get_tracks($scoid,$userid,$attempt='') {
if ($tracks = get_records_select('scorm_scoes_track',"userid=$userid AND scoid=$scoid".$attemptsql,'element ASC')) {
$usertrack->userid = $userid;
$usertrack->scoid = $scoid;
// Defined in order to unify scorm1.2 and scorm2004
$usertrack->score_raw = '';
$usertrack->status = '';
$usertrack->total_time = '00:00:00';
$usertrack->session_time = '00:00:00';
$usertrack->timemodified = 0;
// Added by Pham Minh Duc
$usertrack->score_scaled = '';
$usertrack->success_status = '';
$usertrack->attempt_status = '';
$usertrack->satisfied_status = '';
// End Add
foreach ($tracks as $track) {
$element = $track->element;
$usertrack->{$element} = $track->value;
switch ($element) {
// Added by Pham Minh Duc
case 'cmi.attempt_status':
$usertrack->status = $track->value;
$usertrack->attempt_status = $track->value;
break;
case 'cmi.success_status':
$usertrack->success_status = $track->value;
if ($track->value=='passed'){
$usertrack->satisfied_status = 'satisfied';
}
if ($track->value=='failed'){
$usertrack->satisfied_status = 'notSatisfied';
}
break;
case 'cmi.score.scaled':
$usertrack->score_scaled = $track->value;
break;
// End Add
case 'cmi.core.lesson_status':
case 'cmi.completion_status':
if ($track->value == 'not attempted') {
@ -285,49 +299,130 @@ function scorm_get_user_data($userid) {
return get_record('user','id',$userid,'','','','','firstname, lastname, picture');
}
function scorm_grade_user($scoes, $userid, $grademethod=VALUESCOES) {
$scores = NULL;
$scores->scoes = 0;
$scores->values = 0;
$scores->max = 0;
$scores->sum = 0;
if (!$scoes) {
return '';
function scorm_grade_user_attempt($scorm, $userid, $attempt=1, $time=false) {
$attemptscore = NULL;
$attemptscore->scoes = 0;
$attemptscore->values = 0;
$attemptscore->max = 0;
$attemptscore->sum = 0;
$attemptscore->lastmodify = 0;
if (!$scoes = get_records('scorm_scoes','scorm',$scorm->id)) {
return NULL;
}
$current = current($scoes);
$attempt = scorm_get_last_attempt($current->scorm, $userid);
$grademethod = $scorm->grademethod % 10;
foreach ($scoes as $sco) {
if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
if (($userdata->status == 'completed') || ($userdata->status == 'passed')) {
$scores->scoes++;
$attemptscore->scoes++;
}
if (!empty($userdata->score_raw)) {
$scores->values++;
$scores->sum += $userdata->score_raw;
$scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
$attemptscore->values++;
$attemptscore->sum += $userdata->score_raw;
$attemptscore->max = ($userdata->score_raw > $attemptscore->max)?$userdata->score_raw:$attemptscore->max;
if (isset($userdata->timemodified) && ($userdata->timemodified > $attemptscore->lastmodify)) {
$attemptscore->lastmodify = $userdata->timemodified;
} else {
$attemptscore->lastmodify = 0;
}
}
}
}
switch ($grademethod) {
case VALUEHIGHEST:
return $scores->max;
case GRADEHIGHEST:
$score = $attemptscore->max;
break;
case VALUEAVERAGE:
if ($scores->values > 0) {
return $scores->sum/$scores->values;
case GRADEAVERAGE:
if ($attemptscore->values > 0) {
$score = $attemptscore->sum/$attemptscore->values;
} else {
return 0;
$score = 0;
}
break;
case VALUESUM:
return $scores->sum;
case GRADESUM:
$score = $attemptscore->sum;
break;
case VALUESCOES:
return $scores->scoes;
case GRADESCOES:
$score = $attemptscore->scoes;
break;
}
if ($time) {
$result = new stdClass();
$result->score = $score;
$result->time = $attemptscore->lastmodify;
} else {
$result = $score;
}
return $result;
}
function scorm_grade_user($scorm, $userid, $time=false) {
$whatgrade = intval($scorm->grademethod / 10);
switch ($whatgrade) {
case FIRSTATTEMPT:
return scorm_grade_user_attempt($scorm, $userid, 1, $time);
break;
case LASTATTEMPT:
return scorm_grade_user_attempt($scorm, $userid, scorm_get_last_attempt($scorm->id, $userid), $time);
break;
case HIGHESTATTEMPT:
$lastattempt = scorm_get_last_attempt($scorm->id, $userid);
$maxscore = 0;
$attempttime = 0;
for ($attempt = 1; $attempt <= $lastattempt; $attempt++) {
$attemptscore = scorm_grade_user_attempt($scorm, $userid, $attempt, $time);
if ($time) {
if ($attemptscore->score > $maxscore) {
$maxscore = $attemptscore->score;
$attempttime = $attemptscore->time;
}
} else {
$maxscore = $attemptscore > $maxscore ? $attemptscore: $maxscore;
}
}
if ($time) {
$result = new stdClass();
$result->score = $maxscore;
$result->time = $attempttime;
return $result;
} else {
return $maxscore;
}
break;
case AVERAGEATTEMPT:
$lastattempt = scorm_get_last_attempt($scorm->id, $userid);
$sumscore = 0;
for ($attempt = 1; $attempt <= $lastattempt; $attempt++) {
$attemptscore = scorm_grade_user_attempt($scorm, $userid, $attempt, $time);
if ($time) {
$sumscore += $attemptscore->score;
} else {
$sumscore += $attemptscore;
}
}
if ($lastattempt > 0) {
$score = $sumscore / $lastattempt;
} else {
$score = 0;
}
if ($time) {
$result = new stdClass();
$result->score = $score;
$result->time = $attemptscore->time;
return $result;
} else {
return $score;
}
break;
}
}
function scorm_count_launchable($scormid,$organization) {
@ -345,32 +440,6 @@ function scorm_get_last_attempt($scormid, $userid) {
}
}
function scorm_parse($scorm) {
global $CFG,$repositoryconfigfile;
// Parse scorm manifest
if ($scorm->pkgtype == 'AICC') {
require_once('datamodels/aicclib.php');
$scorm->launch = scorm_parse_aicc($scorm->dir.'/'.$scorm->id,$scorm->id);
} else {
require_once('datamodels/scormlib.php');
$reference = $scorm->reference;
if ($scorm->reference[0] == '#') {
require_once($repositoryconfigfile);
$reference = $CFG->repository.substr($scorm->reference,1).'/imsmanifest.xml';
} else if (substr($reference,0,7) != 'http://') {
$reference = $CFG->dataroot.'/'.$scorm->course.'/'.$scorm->reference;
}
if (basename($reference) != 'imsmanifest.xml') {
$scorm->launch = scorm_parse_scorm($scorm->dir.'/'.$scorm->id,$scorm->id);
} else {
$scorm->launch = scorm_parse_scorm(dirname($reference),$scorm->id);
}
}
return $scorm->launch;
}
function scorm_course_format_display($user,$course) {
global $CFG;
@ -464,12 +533,13 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
<div class="center">
<form name="theform" method="post" action="<?php echo $CFG->wwwroot ?>/mod/scorm/player.php?id=<?php echo $cm->id ?>"<?php echo $scorm->popup == 1?' target="newwin"':'' ?>>
<?php
if ($scorm->hidebrowse == 0) {
print_string("mode","scorm");
echo ': <input type="radio" id="b" name="mode" value="browse" /><label for="b">'.get_string('browse','scorm').'</label>'."\n";
if ($incomplete === true) {
echo '<input type="radio" id="n" name="mode" value="normal" checked="checked" /><label for="n">'.get_string('normal','scorm')."</label>\n";
} else {
echo '<input type="radio" id="r" name="mode" value="review" checked="checked" /><label for="r">'.get_string('review','scorm')."</label>\n";
}
} else {
if ($incomplete === true) {
@ -495,4 +565,30 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
<?php
}
function scorm_parse($scorm) {
global $CFG,$repositoryconfigfile;
// Parse scorm manifest
if ($scorm->pkgtype == 'AICC') {
require_once('datamodels/aicclib.php');
$scorm->launch = scorm_parse_aicc($scorm->dir.'/'.$scorm->id,$scorm->id);
} else {
require_once('datamodels/scormlib.php');
$reference = $scorm->reference;
if ($scorm->reference[0] == '#') {
require_once($repositoryconfigfile);
$reference = $CFG->repository.substr($scorm->reference,1).'/imsmanifest.xml';
} else if (substr($reference,0,7) != 'http://') {
$reference = $CFG->dataroot.'/'.$scorm->course.'/'.$scorm->reference;
}
if (basename($reference) != 'imsmanifest.xml') {
$scorm->launch = scorm_parse_scorm($scorm->dir.'/'.$scorm->id,$scorm->id);
} else {
$scorm->launch = scorm_parse_scorm(dirname($reference),$scorm->id);
}
}
return $scorm->launch;
}
?>

View File

@ -75,6 +75,7 @@
$attempt = scorm_get_last_attempt($scorm->id, $USER->id);
if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
$attempt++;
$mode = 'normal';
}
$attemptstr = '&amp;attempt=' . $attempt;

View File

@ -4,7 +4,7 @@
require_once("../../config.php");
require_once('locallib.php');
$id = optional_param('id', '', PARAM_INT); // Course Module ID, or
$a = optional_param('a', '', PARAM_INT); // SCORM ID
$b = optional_param('b', '', PARAM_INT); // SCO ID
@ -85,6 +85,7 @@
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?id=$cm->id\">$strreport</a>
-> <a href=\"report.php?a=$a&user=$user&attempt=$attempt\">$strattempt $attempt - ".fullname($userdata)."</a> -> $sco->title",
"", "", true);
}
@ -118,6 +119,11 @@
$table->wrap[] = 'nowrap';
$table->size[] = '*';
$table->head[]= get_string('score','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);
@ -131,6 +137,8 @@
$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'));
$row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $a);
$table->data[] = $row;
}
}
@ -141,7 +149,6 @@
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\">".
@ -180,6 +187,7 @@
$trackdata->total_time = '&nbsp;';
$detailslink = '&nbsp;';
}
$strstatus = get_string($trackdata->status,'scorm');
$row[] = '<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
$strstatus.'">&nbsp;'.format_string($sco->title);
$row[] = get_string($trackdata->status,'scorm');
@ -299,6 +307,7 @@
$interactionid = 'cmi.interactions.'.$i.'.id';
}
if ($existinteraction) {
echo '<h3>'.get_string('interactions','scorm').'</h3>';
echo '<h3>'.get_string('interactions','scorm').'</h3>';
print_table($table);
}
@ -375,8 +384,8 @@
error('Missing script parameter');
}
}
if (empty($noheader)) {
print_footer($course);
}