Added multiple attempts support
authorbobopinna <bobopinna>
Tue, 29 Nov 2005 14:54:39 +0000 (14:54 +0000)
committerbobopinna <bobopinna>
Tue, 29 Nov 2005 14:54:39 +0000 (14:54 +0000)
13 files changed:
mod/scorm/aicc.php
mod/scorm/backuplib.php
mod/scorm/datamodel.php
mod/scorm/db/mysql.php
mod/scorm/db/mysql.sql
mod/scorm/db/postgres7.php
mod/scorm/db/postgres7.sql
mod/scorm/locallib.php
mod/scorm/player.php
mod/scorm/report.php
mod/scorm/restorelib.php
mod/scorm/version.php
mod/scorm/view.php

index 4433291..1a51fee 100755 (executable)
         } 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;
index 454156b..d833b68 100755 (executable)
                 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));
index 59853cb..1bde3ce 100755 (executable)
     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;
index 04675d1..1ae99bd 100755 (executable)
@@ -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;
 }
 ?>
index bdea7c0..f099af1 100755 (executable)
@@ -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',
index dfb9b64..40f1e1b 100755 (executable)
@@ -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;
 }
 ?>
index f240fd4..90d9ae8 100755 (executable)
@@ -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',
index bd59b17..38e2567 100755 (executable)
@@ -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; 
index c90ba8b..fd1cf62 100755 (executable)
@@ -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 = '&amp;mode='.$mode;
     $modepop = '&mode='.$mode;
+    $attemptstr = '';
     if ((!$result->incomplete) && ($result->attemptleft > 0)) {
         $attemptstr = '&amp;attempt=new';
-        $attemptpop = '&attempt=new';
     }
 
     $SESSION->scorm_scoid = $sco->id;
 ?>
             </div>
 <?php
-    } // The end of the very test
+    } // The end of the very big test
 ?>
             <div id="scormobject" class="right">
 <?php
index 7529777..d141b1d 100755 (executable)
@@ -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)) {
index 4a96153..be0eedc 100755 (executable)
             $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();
 
index e26b74d..66c0c3b 100755 (executable)
@@ -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)?
 
index 6967130..d104163 100755 (executable)
                 $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();