===============================================
-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)
<?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;
}
?>
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`
);
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));
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)) {
// $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) {
$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) {
$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
);
// 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]['#'];
$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;
}
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)) {
/// 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
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');
}
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";