From a30b6819fc677d26af69fe4b92ef2209d2024c43 Mon Sep 17 00:00:00 2001 From: bobopinna Date: Tue, 26 Sep 2006 07:56:07 +0000 Subject: [PATCH] Fixed some problems with reporting and multiattempts --- mod/scorm/index.php | 7 +- mod/scorm/lib.php | 95 ++----------- mod/scorm/locallib.php | 296 +++++++++++++++++++++++++++-------------- mod/scorm/player.php | 1 + mod/scorm/report.php | 17 ++- 5 files changed, 225 insertions(+), 191 deletions(-) diff --git a/mod/scorm/index.php b/mod/scorm/index.php index c332b793e8..37b7d3e4a7 100755 --- a/mod/scorm/index.php +++ b/mod/scorm/index.php @@ -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 = ''.get_string('viewallreports','scorm',$trackedusers->c).''; + $reportshow = ''.get_string('viewallreports','scorm',$trackedusers->c).''; } 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, "coursemodule\">".format_string($scorm->name,true)."", - format_text($scorm->summary),$reportshow); + format_text($scorm->summary), $reportshow); } else { //Show normal if the mod is visible $table->data[] = array ($tt, "coursemodule\">".format_string($scorm->name,true)."", @@ -92,4 +92,3 @@ print_footer($course); ?> - diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 064c0a5551..c7338ff099 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -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').': '.$scores->max; - $return->time = $scores->lastmodify; - } - break; - case GRADEAVERAGE: - if ($scores->values > 0) { - $return->info = get_string('score','scorm').': '.$scores->sum/$scores->values; - $return->time = $scores->lastmodify; - } - break; - case GRADESUM: - if ($scores->values > 0) { - $return->info = get_string('score','scorm').': '.$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').': '.$scores->completed.'
'; - $scores->notattempted -= $scores->completed; - } - if (isset($scores->passed)) { - $return->info .= get_string('passed','scorm').': '.$scores->passed.'
'; - $scores->notattempted -= $scores->passed; - } - if (isset($scores->failed)) { - $return->info .= get_string('failed','scorm').': '.$scores->failed.'
'; - $scores->notattempted -= $scores->failed; - } - if (isset($scores->incomplete)) { - $return->info .= get_string('incomplete','scorm').': '.$scores->incomplete.'
'; - $scores->notattempted -= $scores->incomplete; - } - if (isset($scores->browsed)) { - $return->info .= get_string('browsed','scorm').': '.$scores->browsed.'
'; - $scores->notattempted -= $scores->browsed; - } - $return->time = $scores->lastmodify; - if ($return->info == '') { - $return = NULL; - } else { - $return->info .= get_string('notattempted','scorm').': '.$scores->notattempted.'
'; - } - 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; diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 7a279fa8ea..eb15905448 100755 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -1,5 +1,66 @@ 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.'
'; - $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='') {
popup == 1?' target="newwin"':'' ?>> hidebrowse == 0) { print_string("mode","scorm"); echo ': '."\n"; if ($incomplete === true) { echo '\n"; + } else { + echo '\n"; } } else { if ($incomplete === true) { @@ -495,4 +565,30 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') { 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; +} + ?> diff --git a/mod/scorm/player.php b/mod/scorm/player.php index 15879a80db..6aff5084b3 100755 --- a/mod/scorm/player.php +++ b/mod/scorm/player.php @@ -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 = '&attempt=' . $attempt; diff --git a/mod/scorm/report.php b/mod/scorm/report.php index 749a977d94..ea4bf823b1 100755 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -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 id\">$strscorms -> id\">".format_string($scorm->name,true)." + -> id\">$strreport -> $strattempt $attempt - ".fullname($userdata)." -> $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 '
'."\n"; print_user_picture($user, $course->id, $userdata->picture, false, false); echo "wwwroot/user/view.php?id=$user&course=$course->id\">". @@ -180,6 +187,7 @@ $trackdata->total_time = ' '; $detailslink = ' '; } + $strstatus = get_string($trackdata->status,'scorm'); $row[] = ''.$strstatus.' '.format_string($sco->title); $row[] = get_string($trackdata->status,'scorm'); @@ -299,6 +307,7 @@ $interactionid = 'cmi.interactions.'.$i.'.id'; } if ($existinteraction) { + echo '

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

'; echo '

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

'; print_table($table); } @@ -375,8 +384,8 @@ error('Missing script parameter'); } } - - + + if (empty($noheader)) { print_footer($course); } -- 2.39.5