diff --git a/mod/scorm/index.php b/mod/scorm/index.php
index c332b793e83..37b7d3e4a75 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 064c0a55515..c7338ff0994 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 7a279fa8ea2..eb15905448d 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='') {