Added multiple attempts support
This commit is contained in:
+3
-3
@@ -30,11 +30,11 @@
|
||||
} else {
|
||||
$newattempt = '';
|
||||
}
|
||||
if ($lastattempt = get_record('scorm_sco_tracks', 'user', $USER->id, 'scorm', $scorm->id, 'sco', $scoid,'max(attempt) as a')) {
|
||||
if ($lastattempt = get_record('scorm_scoes_track', 'userid', $USER->id, 'scorm', $scorm->id, 'scoid', $scoid,'max(attempt) as a')) {
|
||||
if ($newattempt == 'new') {
|
||||
$attempt = $lastattempt['a']+1;
|
||||
$attempt = $lastattempt->a + 1;
|
||||
} else {
|
||||
$attempt = $lastattempt['a'];
|
||||
$attempt = $lastattempt->a;
|
||||
}
|
||||
} else {
|
||||
$attempt = 1;
|
||||
|
||||
@@ -50,8 +50,10 @@
|
||||
fwrite ($bf,full_tag("SUMMARY",4,false,$scorm->summary));
|
||||
fwrite ($bf,full_tag("HIDEBROWSE",4,false,$scorm->hidebrowse));
|
||||
fwrite ($bf,full_tag("HIDETOC",4,false,$scorm->hidetoc));
|
||||
fwrite ($bf,full_tag("HIDENAV",4,false,$scorm->hidenav));
|
||||
fwrite ($bf,full_tag("AUTO",4,false,$scorm->auto));
|
||||
fwrite ($bf,full_tag("POPUP",4,false,$scorm->popup));
|
||||
fwrite ($bf,full_tag("OPTIONS",4,false,$scorm->options));
|
||||
fwrite ($bf,full_tag("WIDTH",4,false,$scorm->width));
|
||||
fwrite ($bf,full_tag("HEIGHT",4,false,$scorm->height));
|
||||
fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$scorm->timemodified));
|
||||
|
||||
@@ -36,11 +36,11 @@
|
||||
if (confirm_sesskey() && (!empty($scoid))) {
|
||||
$result = true;
|
||||
if (isstudent($course->id) || (isteacher($course->id) && !isadmin()) {
|
||||
if ($lastattempt = get_record('scorm_sco_tracks', 'user', $USER->id, 'scorm', $scorm->id, 'sco', $scoid,'max(attempt) as a')) {
|
||||
if ($lastattempt = get_record('scorm_scoes_track', 'userid', $USER->id, 'scorm', $scorm->id, 'scoid', $scoid,'max(attempt) as a')) {
|
||||
if ($newattempt == 'new') {
|
||||
$attempt = $lastattempt['a']+1;
|
||||
$attempt = $lastattempt->a + 1;
|
||||
} else {
|
||||
$attempt = $lastattempt['a'];
|
||||
$attempt = $lastattempt->a;
|
||||
}
|
||||
} else {
|
||||
$attempt = 1;
|
||||
|
||||
@@ -208,6 +208,10 @@ function scorm_upgrade($oldversion) {
|
||||
modify_database('','ALTER TABLE prefix_scorm_scoes_track ADD UNIQUE track (userid,scormid,scoid,attempt,element);');
|
||||
}
|
||||
|
||||
if ($oldversion < 2005102800) {
|
||||
table_column("scorm", "", "maxattempt", "INT", "10", "UNSIGNED", "1", "NOT NULL", "maxgrade");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -10,6 +10,7 @@ CREATE TABLE prefix_scorm (
|
||||
version varchar(9) NOT NULL default '',
|
||||
maxgrade float(3) NOT NULL default '0',
|
||||
grademethod tinyint(2) NOT NULL default '0',
|
||||
maxattempt int(10) NOT NULL default '1',
|
||||
launch int(10) unsigned NOT NULL default '0',
|
||||
summary text NOT NULL,
|
||||
hidebrowse tinyint(1) NOT NULL default '0',
|
||||
|
||||
@@ -216,6 +216,14 @@ function scorm_upgrade($oldversion) {
|
||||
table_column("scorm", "", "options", "varchar", "255", "", "", "NOT NULL","popup");
|
||||
}
|
||||
|
||||
if ($oldversion < 2005092600) {
|
||||
table_column("scorm_scoes_track", "", "attempt", "integer", "", "UNSIGNED", "1", "NOT NULL", "scoid");
|
||||
execute_sql("DROP INDEX {$CFG->prefix}scorm_scoes_track_scormid_idx", false);
|
||||
modify_database('','ALTER TABLE prefix_scorm_scoes_track ADD UNIQUE track (userid,scormid,scoid,attempt,element);');
|
||||
}
|
||||
|
||||
if ($oldversion < 2005102800) {
|
||||
table_column("scorm", "", "maxattempt", "integer", "", "UNSIGNED", "1", "NOT NULL", "maxgrade");
|
||||
return true;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -9,6 +9,7 @@ CREATE TABLE prefix_scorm (
|
||||
reference varchar(255) NOT NULL default '',
|
||||
maxgrade real NOT NULL default '0',
|
||||
grademethod integer NOT NULL default '0',
|
||||
maxattempt integer NOT NULL default '1',
|
||||
launch integer NOT NULL default '0',
|
||||
summary text NOT NULL default '',
|
||||
hidebrowse integer NOT NULL default '0',
|
||||
|
||||
+19
-7
@@ -384,8 +384,8 @@ function scorm_count_launchable($scormid,$organization) {
|
||||
return count_records_select('scorm_scoes',"scorm=$scormid AND organization='$organization' AND launch<>''");
|
||||
}
|
||||
|
||||
function scorm_get_toc($scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$play=false) {
|
||||
global $USER, $CFG;
|
||||
function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$play=false) {
|
||||
global $CFG;
|
||||
|
||||
$strexpand = get_string('expcoll','scorm');
|
||||
|
||||
@@ -403,16 +403,20 @@ function scorm_get_toc($scorm,$liststyle,$currentorg='',$scoid='',$mode='normal'
|
||||
}
|
||||
if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
|
||||
$usertracks = array();
|
||||
$maxattempt = 0;
|
||||
foreach ($scoes as $sco) {
|
||||
if (!empty($sco->launch)) {
|
||||
if ($usertrack=scorm_get_tracks($sco->id,$USER->id)) {
|
||||
if ($usertrack=scorm_get_tracks($sco->id,$user->id)) {
|
||||
if ($usertrack->status == '') {
|
||||
$usertrack->status = 'notattempted';
|
||||
}
|
||||
$attempt = scorm_get_last_attempt($sco->id, $user->id);
|
||||
$maxattempt = $attempt > $maxattempt ? $attempt : $maxattempt;
|
||||
$usertracks[$sco->identifier] = $usertrack;
|
||||
}
|
||||
}
|
||||
}
|
||||
$result->attemptleft = $scorm->maxattempt - $maxattempt;
|
||||
|
||||
$level=0;
|
||||
$sublist=1;
|
||||
@@ -539,14 +543,22 @@ function scorm_get_toc($scorm,$liststyle,$currentorg='',$scoid='',$mode='normal'
|
||||
return $result;
|
||||
}
|
||||
|
||||
function scorm_get_last_attempt($scoid, $userid) {
|
||||
/// Find the last attempt number for the given user id and sco
|
||||
if ($lastattempt = get_record('scorm_scoes_track', 'userid', $userid, 'scoid', $scoid, '', '', 'max(attempt) as a')) {
|
||||
if (empty($lastattempt->a)) {
|
||||
return '1';
|
||||
} else {
|
||||
return $lastattempt->a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function scorm_get_tracks($scoid,$userid) {
|
||||
/// Gets all tracks of specified sco and user
|
||||
global $CFG;
|
||||
|
||||
$attemptsql = '';
|
||||
if ($lastattempt = get_record('scorm_sco_tracks', 'user', $USER->id, 'scorm', $scorm->id, '', '', 'max(attempt) as a')) {
|
||||
$attemptsql = ' AND attempt='.$lastattempt;
|
||||
}
|
||||
$attemptsql = ' AND attempt=' . scorm_get_last_attempt($scoid, $userid);
|
||||
if ($tracks = get_records_select('scorm_scoes_track',"userid=$userid AND scoid=$scoid".$attemptsql,'element ASC')) {
|
||||
$usertrack->userid = $userid;
|
||||
$usertrack->scoid = $scoid;
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
//
|
||||
// TOC processing
|
||||
//
|
||||
$result = scorm_get_toc($scorm,'structurelist',$currentorg,$scoid,$mode,true);
|
||||
$result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,true);
|
||||
$sco = $result->sco;
|
||||
|
||||
if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
|
||||
@@ -97,9 +97,9 @@
|
||||
$scoidpop = '&scoid='.$sco->id;
|
||||
$modestr = '&mode='.$mode;
|
||||
$modepop = '&mode='.$mode;
|
||||
$attemptstr = '';
|
||||
if ((!$result->incomplete) && ($result->attemptleft > 0)) {
|
||||
$attemptstr = '&attempt=new';
|
||||
$attemptpop = '&attempt=new';
|
||||
}
|
||||
|
||||
$SESSION->scorm_scoid = $sco->id;
|
||||
@@ -195,7 +195,7 @@
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
} // The end of the very test
|
||||
} // The end of the very big test
|
||||
?>
|
||||
<div id="scormobject" class="right">
|
||||
<?php
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
require_once("../../config.php");
|
||||
require_once('locallib.php');
|
||||
|
||||
optional_param($id, 0, PARAM_NUM); // Course Module ID, or
|
||||
optional_param($a, 0, PARAM_NUM); // SCORM ID
|
||||
optional_param($b, 0, PARAM_NUM); // SCO ID
|
||||
optional_param($user, 0, PARAM_NUM); // User ID
|
||||
$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
|
||||
$user = optional_param('user', '', PARAM_INT); // User ID
|
||||
|
||||
if (!empty($id)) {
|
||||
if (! $cm = get_record("course_modules", "id", $id)) {
|
||||
|
||||
@@ -65,24 +65,48 @@
|
||||
$scorm->summary = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
|
||||
$scorm->hidebrowse = backup_todb($info['MOD']['#']['HIDEBROWSE']['0']['#']);
|
||||
$scorm->hidetoc = backup_todb($info['MOD']['#']['HIDETOC']['0']['#']);
|
||||
$scorm->hidenav = backup_todb($info['MOD']['#']['HIDENAV']['0']['#']);
|
||||
$scorm->auto = backup_todb($info['MOD']['#']['AUTO']['0']['#']);
|
||||
if ($restore->backup_version < 2005040200) {
|
||||
$oldpopup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
|
||||
if (!empty($oldpopup)) {
|
||||
$scorm->popup = 1;
|
||||
// Parse old popup field
|
||||
$options = array();
|
||||
$oldoptions = explode(',',$scorm->popup);
|
||||
foreach ($oldoptions as $oldoption) {
|
||||
list($element,$value) = explode('=',$oldoption);
|
||||
$element = trim($element);
|
||||
$value = trim($value);
|
||||
switch ($element) {
|
||||
case 'width':
|
||||
$scorm->width = $value;
|
||||
break;
|
||||
case 'height':
|
||||
$scorm->height = $value;
|
||||
break;
|
||||
default:
|
||||
$options[] = $element.'='.$value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$scorm->options = implode($options,',');
|
||||
} else {
|
||||
$scorm->popup = 0;
|
||||
$scorm->options = '';
|
||||
$scorm->width = '100%';
|
||||
$scorm->height = 500;
|
||||
}
|
||||
} else {
|
||||
$scorm->popup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
|
||||
}
|
||||
$scorm->width = backup_todb($info['MOD']['#']['WIDTH']['0']['#']);
|
||||
if ($scorm->width == 0) {
|
||||
$scorm->width = 800;
|
||||
}
|
||||
$scorm->height = backup_todb($info['MOD']['#']['HEIGHT']['0']['#']);
|
||||
if ($scorm->height == 0) {
|
||||
$scorm->height = 600;
|
||||
$scorm->width = backup_todb($info['MOD']['#']['WIDTH']['0']['#']);
|
||||
if ($scorm->width == 0) {
|
||||
$scorm->width = '100%';
|
||||
}
|
||||
$scorm->height = backup_todb($info['MOD']['#']['HEIGHT']['0']['#']);
|
||||
if ($scorm->height == 0) {
|
||||
$scorm->height = 500;
|
||||
}
|
||||
}
|
||||
$scorm->timemodified = time();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$module->version = 2005092600; // The (date) version of this module
|
||||
$module->version = 2005102800; // The (date) version of this module
|
||||
$module->requires = 2005060200; // The version of Moodle that is required
|
||||
$module->cron = 0; // How often should cron check this module (seconds)?
|
||||
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@
|
||||
$orgidentifier = $org->organization;
|
||||
}
|
||||
}
|
||||
$result = scorm_get_toc($scorm,'structurelist',$orgidentifier);
|
||||
$result = scorm_get_toc($USER,$scorm,'structurelist',$orgidentifier);
|
||||
$incomplete = $result->incomplete;
|
||||
echo $result->toc;
|
||||
print_simple_box_end();
|
||||
|
||||
Reference in New Issue
Block a user