]> git.mjollnir.org Git - moodle.git/commitdiff
merging changes from MOODLE_16_STABLE
authorskodak <skodak>
Mon, 31 Jul 2006 18:10:02 +0000 (18:10 +0000)
committerskodak <skodak>
Mon, 31 Jul 2006 18:10:02 +0000 (18:10 +0000)
mod/hotpot/README.TXT
mod/hotpot/db/postgres7.php
mod/hotpot/db/postgres7.sql
mod/hotpot/restorelib.php
mod/hotpot/version.php
mod/lesson/db/postgres7.php
mod/lesson/view.php

index 8a58a9916fd8caf21571e50bf34405a1a2cc372d..443046b787d48c40730b33b7426537f2719a2604 100644 (file)
@@ -1,13 +1,14 @@
 ===============================================
-This is v2.1.20 of the HotPot module for Moodle
+This is v2.1.21 of the HotPot module for Moodle
 ===============================================
 
    This module allows teachers to administer Hot Potatoes and TexToys quizzes via Moodle.
    It has been tested on:
       - Hot Potatoes 6
-      - Moodle 1.1 thru 1.6
+      - Moodle 1.1 thru 1.7
       - PHP 4.1 thru 5.1.2
-      - MySQL and PostgreSQL databases
+      - MySQL 4.x thru 5.0
+      - PostgreSQL 7.3 thru 8.2
 
    This module may be distributed under the terms of the General Public License
    (see http://www.gnu.org/licenses/gpl.txt for details)
index e5d5252217752eefa3ea9f7e3e6fb96d27b77fcc..e5f80e4f94d0b62c2b6ead3a07eb2b25fa53e7c1 100644 (file)
@@ -1,90 +1,51 @@
 <?PHP
 function hotpot_upgrade($oldversion) {
-       global $CFG;
-       $ok = true;
-
-       // set path to update functions
-       $update_to_v2 = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php";
-
-       // update from HotPot v1 to HotPot v2
-       if ($oldversion < 2005031400) {
-               require_once $update_to_v2;
-               $ok = $ok && hotpot_update_to_v2_from_v1();
-       }
-       // update to HotPot v2.1
-       if ($oldversion < 2005090700) {
-               require_once $update_to_v2;
-               $ok = $ok && hotpot_update_to_v2_1();
-       }
-       if ($oldversion > 2005031419 && $oldversion < 2005090702) {
-               // update to from HotPot v2.1.0 or v2.1.1
-               require_once $update_to_v2;
-               $ok = $ok && hotpot_update_to_v2_1_2();
-       }
-       if ($oldversion < 2005090706) {
-               require_once $update_to_v2;
-               $ok = $ok && hotpot_update_to_v2_1_6();
-       }
-       if ($oldversion < 2005090708) {
-               require_once $update_to_v2;
-               $ok = $ok && hotpot_update_to_v2_1_8();
-       }
-       if ($oldversion < 2006042103) {
-               require_once $update_to_v2;
-               $ok = $ok && hotpot_update_to_v2_1_16();
-       }
-       if ($oldversion < 2006042602) {
-               require_once $update_to_v2;
-               $ok = $ok && hotpot_update_to_v2_1_17();
-       }
-       if ($oldversion < 2006042803) {
-               require_once $update_to_v2;
-               $ok = $ok && hotpot_update_to_v2_1_18();
-       }
-
-
-        if ($oldversion < 2006050201) {
-
-            modify_database('', 'ALTER TABLE prefix_hotpot
-                ALTER COLUMN studentfeedbackurl SET DEFAULT \'\',
-                ALTER COLUMN studentfeedbackurl SET NOT NULL,
-                ALTER COLUMN clickreporting SET DEFAULT 0,
-                ALTER COLUMN studentfeedback SET DEFAULT 0');
-
-            modify_database('', 'ALTER TABLE prefix_hotpot_strings
-                ALTER COLUMN string SET DEFAULT \'\'');
-
-            modify_database('', 'ALTER TABLE prefix_hotpot_responses
-                ALTER COLUMN hints TYPE int2,
-                ALTER COLUMN hints SET DEFAULT 0,
-                ALTER COLUMN ignored SET DEFAULT \'\',
-                ALTER COLUMN ignored SET NOT NULL,
-                ALTER COLUMN score TYPE int2,
-                ALTER COLUMN score SET DEFAULT 0,
-                ALTER COLUMN correct SET DEFAULT \'\',
-                ALTER COLUMN correct SET NOT NULL,
-                ALTER COLUMN weighting TYPE int2,
-                ALTER COLUMN weighting SET DEFAULT 0,
-                ALTER COLUMN wrong SET DEFAULT \'\',
-                ALTER COLUMN wrong SET NOT NULL,
-                ALTER COLUMN checks TYPE int2,
-                ALTER COLUMN checks SET DEFAULT 0,
-                ALTER COLUMN clues TYPE int2,
-                ALTER COLUMN clues SET DEFAULT 0');
-
-            modify_database('', 'ALTER TABLE prefix_hotpot_questions
-                ALTER COLUMN "type" SET DEFAULT 0');
-
-            modify_database('', 'ALTER TABLE prefix_hotpot_attempts
-                ALTER COLUMN penalties TYPE smallint,
-                ALTER COLUMN penalties SET DEFAULT 0,
-                ALTER COLUMN score TYPE smallint,
-                ALTER COLUMN score SET DEFAULT 0,
-                ALTER COLUMN status SET DEFAULT 1');
-
-        }
-
-
-        return $ok;
+    global $CFG;
+    $ok = true;
+
+    // set path to update functions
+    $update_to_v2 = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php";
+
+    // update from HotPot v1 to HotPot v2
+    if ($oldversion < 2005031400) {
+        require_once $update_to_v2;
+        $ok = $ok && hotpot_update_to_v2_from_v1();
+    }
+
+    // update to HotPot v2.1
+    if ($oldversion < 2005090700) {
+        require_once $update_to_v2;
+        $ok = $ok && hotpot_update_to_v2_1();
+    }
+    if ($oldversion > 2005031419 && $oldversion < 2005090702) {
+        require_once $update_to_v2;
+        $ok = $ok && hotpot_update_to_v2_1_2();
+    }
+    if ($oldversion < 2005090706) {
+        require_once $update_to_v2;
+        $ok = $ok && hotpot_update_to_v2_1_6();
+    }
+    if ($oldversion < 2005090708) {
+        require_once $update_to_v2;
+        $ok = $ok && hotpot_update_to_v2_1_8();
+    }
+    if ($oldversion < 2006042103) {
+        require_once $update_to_v2;
+        $ok = $ok && hotpot_update_to_v2_1_16();
+    }
+    if ($oldversion < 2006042602) {
+        require_once $update_to_v2;
+        $ok = $ok && hotpot_update_to_v2_1_17();
+    }
+    if ($oldversion < 2006042803) {
+        require_once $update_to_v2;
+        $ok = $ok && hotpot_update_to_v2_1_18();
+    }
+    if ($oldversion < 2006071600) {
+        require_once $update_to_v2;
+        $ok = $ok && hotpot_update_to_v2_1_21();
+    }
+
+    return $ok;
 }
 ?>
index fb36061c9270006008fd650cffe7ee8d6d5e89ad..ceadffd09d1686c2c229f317a8a5c7f24807ce07 100644 (file)
@@ -79,7 +79,7 @@ CREATE TABLE prefix_hotpot_questions (
 COMMENT ON TABLE prefix_hotpot_questions IS 'details about questions in Hot Potatoes quiz attempts';
 
 CREATE INDEX prefix_hotpot_questions_hotpot_idx ON prefix_hotpot_questions (hotpot);
-CREATE INDEX prefix_hotpot_questions_name_idx ON prefix_hotpot_questions (SUBSTR(name,20));
+CREATE INDEX prefix_hotpot_questions_name_idx ON prefix_hotpot_questions (SUBSTR("name",20));
 
 #
 # Table structure for table `hotpot_responses`
@@ -113,4 +113,4 @@ CREATE TABLE prefix_hotpot_strings (
 );
 COMMENT ON TABLE prefix_hotpot_strings IS 'strings used in Hot Potatoes questions and responses';
 
-CREATE INDEX prefix_hotpot_strings_string_idx ON prefix_hotpot_strings (SUBSTR(string,20));
+CREATE INDEX prefix_hotpot_strings_string_idx ON prefix_hotpot_strings (SUBSTR("string",20));
index 20faec8b6d1aad07c767d2d775aa70a89095230a..c68b2f0f6f1b05409162903226635a19722a6b83 100644 (file)
@@ -203,7 +203,7 @@ function hotpot_restore_details(&$restore, $status, &$xml, &$record) {
     if (empty($record->details)) {
         $status = true;
     } else {
-        unset($details);
+        $details = new stdClass();
         $details->attempt = $record->id;
         $details->details = $record->details;
         if (insert_record('hotpot_details', $details)) {
@@ -226,7 +226,8 @@ function hotpot_restore_records(&$restore, $status, &$xml, $table, $foreign_keys
     // $record_TAG  : (optional) the name of an XML tag which starts a single record
     //    If no $record_TAG is specified, the block of records is assumed to be a single record
     // other parameters are explained in "hotpot_restore_record" below
-    $i = 0;
+    
+    $i = 0; // index for $records_TAG
     do {
         unset($xml_records);
         if ($records_TAG) {
@@ -238,10 +239,8 @@ function hotpot_restore_records(&$restore, $status, &$xml, $table, $foreign_keys
                 $xml_records = &$xml;
             }
         }
-        if (empty($xml_records)) {
-            // do nothing
-        } else {
-            $ii = 0;
+        if (isset($xml_records)) {
+            $ii = 0; // index for $record_TAG
             do {
                 unset($xml_record);
                 if ($record_TAG) {
@@ -253,9 +252,7 @@ function hotpot_restore_records(&$restore, $status, &$xml, $table, $foreign_keys
                         $xml_record = &$xml_records;
                     }
                 }
-                if (empty($xml_record)) {
-                    // do nothing
-                } else {
+                if (isset($xml_record)) {
                     $status = hotpot_restore_record(
                         $restore, $status, $xml_record, $table, $foreign_keys, $more_restore, $secondary_key
                     );
@@ -283,7 +280,16 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys,
     //    the name of the secondary key field, if any, in the current $record.
     //    If this field is specified, then the current record will only be added
     //    if the $record->$secondarykey value does not already exist in $table
-    unset($record);
+
+    // maintain a cache of info on table columns
+    static $table_columns = array();
+    if (empty($table_columns[$table])) {
+        global $CFG, $db;
+        $table_columns[$table] = $db->MetaColumns("$CFG->prefix$table");
+    }
+
+    // get values for fields in this record
+    $record = new stdClass();
     $TAGS = array_keys($xml);
     foreach ($TAGS as $TAG) {
         $value = $xml[$TAG][0]['#'];
@@ -292,41 +298,65 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys,
             $record->$tag = backup_todb($value);
         }
     }
+
+    // update secondary keys, if any
     $ok = true;
     foreach ($foreign_keys as $key=>$value) {
         if (is_numeric($value)) {
             $record->$key = $value;
         } else {
-            if (empty($record->$key)) {
-                $record->$key = NULL;
-            } else {
-                $key_table = $value;
-                $new_ids = array();
+            $key_table = $value;
+            $new_ids = array();
+            if (isset($record->$key)) {
                 $old_ids = explode(',', $record->$key);
                 foreach ($old_ids as $old_id) {
-                    $key_record = backup_getid($restore->backup_unique_code, $key_table, $old_id);
-                    if ($key_record) {
-                        $new_ids[] = $key_record->new_id;
+                    if (empty($old_id)) {
+                        // do nothing
                     } else {
-                        // foreign key could not be updated
-                        if (!defined('RESTORE_SILENTLY')) {
-                            print "<ul><li><b>Warning:</b><br>Foreign key could not be updated:<br>";
-                            print "'$key_table' record (old id=$old_id) is missing from backup data<br>";
-                            print "'$table' record ";
-                            if (isset($record->id)) {
-                                print "(old id=$record->id) ";
+                        $key_record = backup_getid($restore->backup_unique_code, $key_table, $old_id);
+                        if ($key_record) {
+                            $new_ids[] = $key_record->new_id;
+                        } else {
+                            // foreign key could not be updated
+                            if (!defined('RESTORE_SILENTLY')) {
+                                print "<ul><li><b>Warning:</b><br>Foreign key could not be updated:<br>";
+                                print "'$key_table' record (old id=$old_id) is missing from backup data<br>";
+                                print "'$table' record ";
+                                if (isset($record->id)) {
+                                    print "(old id=$record->id) ";
+                                }
+                                print "was not restored</li></ul>";
                             }
-                            print "was not restored</li></ul>";
+                            $ok = false; 
                         }
-                        $ok = false; 
                     }
                 }
-                $record->$key = implode(',', $new_ids);
+            }
+            $record->$key = implode(',', $new_ids);
+        }
+    }
+
+    // check all "not null" fields have been set
+    foreach ($table_columns[$table] as $column) {
+        if ($column->not_null) {
+            $name = $column->name;
+            if ($name<>'id' && empty($record->$name)) {
+                if (isset($column->default_value)) {
+                    $default = $column->default_value;
+                } else {
+                    if (preg_match('/int|decimal|double|float|time|year/i', $column->type)) {
+                        $default = 0;
+                    } else {
+                        $default = '';
+                    }
+                }
+                $record->$name = $default;
             }
         }
     }
+
     // check everything is OK so far
-    if ($ok && isset($record)) {
+    if ($ok) {
         // store old record id, if necessary
         if (isset($record->id)) {
             $record->old_id = $record->id;
@@ -343,7 +373,7 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys,
         }
         if (empty($record->id)) {
             // add the $record (and get new id)
-            $record->id = insert_record ($table, $record);
+            $record->id = insert_record($table, $record);
         }
         // check $record was added (or found)
         if (is_numeric($record->id)) {
index f5312d53f7d87d0d9267b929751746cc2836c0f2..f06dafac367fb9a35ac183c9b89f131555f0e747 100644 (file)
@@ -3,9 +3,9 @@
 ///  Code fragment to define the version of hotpot
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
-$module->version  = 2006052200;  // release date of this version (see note below)
-$module->release  = 'v2.1.20';    // human-friendly version name (used in mod/hotpot/lib.php)
-$module->cron     = 0;           // period for cron to check this module (secs)
+$module->version  = 2006071600;   // release date of this version (see note below)
+$module->release  = 'v2.1.21';    // human-friendly version name (used in mod/hotpot/lib.php)
+$module->cron     = 0;            // period for cron to check this module (secs)
 // interpretation of YYYYMMDDXY version numbers
 //     YYYY : year
 //     MM   : month
index fad2d9b161c8c31ed26164045176dda2e9e7aa8e..2a37294c1ac4618146d04a49c5ac59cf64891d1e 100644 (file)
@@ -318,30 +318,38 @@ function lesson_upgrade($oldversion) {
         execute_sql('DROP TABLE '.$CFG->prefix.'lesson_essay', false);
 
         // properly set the correct default values
-        modify_database('', 'ALTER TABLE prefix_lesson
-            ALTER COLUMN activitylink TYPE int8,
-            ALTER COLUMN activitylink SET DEFAULT 0,
-            ALTER COLUMN dependency TYPE int8,
-            ALTER COLUMN dependency SET DEFAULT 0');
+        table_column('lesson', 'activitylink', 'activitylink', 'integer', '8', '', '0');
+        table_column('lesson', 'dependency', 'dependency', 'integer', '8', '', '0');
 
         modify_database('', 'ALTER TABLE prefix_lesson_timer
-            ALTER COLUMN lessontime SET DEFAULT 0,
-            ALTER COLUMN lessonid SET DEFAULT 0,
-            ALTER COLUMN userid SET DEFAULT 0,
+            ALTER COLUMN lessontime SET DEFAULT 0');
+        modify_database('', 'ALTER TABLE prefix_lesson_timer
+            ALTER COLUMN lessonid SET DEFAULT 0');
+        modify_database('', 'ALTER TABLE prefix_lesson_timer
+            ALTER COLUMN userid SET DEFAULT 0');
+        modify_database('', 'ALTER TABLE prefix_lesson_timer
             ALTER COLUMN starttime SET DEFAULT 0');
 
         modify_database('', 'ALTER TABLE prefix_lesson_branch
-            ALTER COLUMN lessonid SET DEFAULT 0,
-            ALTER COLUMN timeseen SET DEFAULT 0,
-            ALTER COLUMN userid SET DEFAULT 0,
-            ALTER COLUMN retry SET DEFAULT 0,
-            ALTER COLUMN pageid SET DEFAULT 0,
+            ALTER COLUMN lessonid SET DEFAULT 0');
+        modify_database('', 'ALTER TABLE prefix_lesson_branch
+            ALTER COLUMN timeseen SET DEFAULT 0');
+        modify_database('', 'ALTER TABLE prefix_lesson_branch
+            ALTER COLUMN userid SET DEFAULT 0');
+        modify_database('', 'ALTER TABLE prefix_lesson_branch
+            ALTER COLUMN retry SET DEFAULT 0');
+        modify_database('', 'ALTER TABLE prefix_lesson_branch
+            ALTER COLUMN pageid SET DEFAULT 0');
+        modify_database('', 'ALTER TABLE prefix_lesson_branch
             ALTER COLUMN flag SET DEFAULT 0');
 
         modify_database('', 'ALTER TABLE prefix_lesson_high_scores
-            ALTER COLUMN nickname SET DEFAULT \'\',
-            ALTER COLUMN lessonid SET DEFAULT 0,
-            ALTER COLUMN gradeid SET DEFAULT 0,
+            ALTER COLUMN nickname SET DEFAULT \'\'');
+        modify_database('', 'ALTER TABLE prefix_lesson_high_scores
+            ALTER COLUMN lessonid SET DEFAULT 0');
+        modify_database('', 'ALTER TABLE prefix_lesson_high_scores
+            ALTER COLUMN gradeid SET DEFAULT 0');
+        modify_database('', 'ALTER TABLE prefix_lesson_high_scores
             ALTER COLUMN userid SET DEFAULT 0');
     }
 
index 3f62919bdeae8d9cb157b5ae6513494b4b509637..e826a47c153458ac346f4c0f960ecd520edc472e 100644 (file)
                         case LESSON_ENDOFBRANCH :
                             echo get_string("endofbranch", "lesson");
                             break;
+                        case LESSON_CLUSTER :
+                            echo get_string("clustertitle", "lesson");
+                            break;
+                        case LESSON_ENDOFCLUSTER :
+                            echo get_string("endofclustertitle", "lesson");
+                            break;
                     }
                     echo "</b></td></tr>\n";
                     $i = 1;
                                 echo "$jumptitle</td></tr>\n";
                             }
                         } else {
-                            if ($lesson->custom && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFBRANCH) {                        
+                            if ($lesson->custom and 
+                                $page->qtype != LESSON_BRANCHTABLE and 
+                                $page->qtype != LESSON_ENDOFBRANCH and
+                                $page->qtype != LESSON_CLUSTER and 
+                                $page->qtype != LESSON_ENDOFCLUSTER) {
                                 echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("score", "lesson")." $i:";
                                 echo "</b></td><td width=\"80%\">\n";
                                 echo "$answer->score</td></tr>\n";