merging changes from MOODLE_16_STABLE

This commit is contained in:
skodak 2006-07-31 18:10:02 +00:00
parent 889e6b46f4
commit a8ff58dd2c
7 changed files with 147 additions and 137 deletions

View 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. This module allows teachers to administer Hot Potatoes and TexToys quizzes via Moodle.
It has been tested on: It has been tested on:
- Hot Potatoes 6 - Hot Potatoes 6
- Moodle 1.1 thru 1.6 - Moodle 1.1 thru 1.7
- PHP 4.1 thru 5.1.2 - 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 This module may be distributed under the terms of the General Public License
(see http://www.gnu.org/licenses/gpl.txt for details) (see http://www.gnu.org/licenses/gpl.txt for details)

View file

@ -1,90 +1,51 @@
<?PHP <?PHP
function hotpot_upgrade($oldversion) { function hotpot_upgrade($oldversion) {
global $CFG; global $CFG;
$ok = true; $ok = true;
// set path to update functions // set path to update functions
$update_to_v2 = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php"; $update_to_v2 = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php";
// update from HotPot v1 to HotPot v2 // update from HotPot v1 to HotPot v2
if ($oldversion < 2005031400) { if ($oldversion < 2005031400) {
require_once $update_to_v2; require_once $update_to_v2;
$ok = $ok && hotpot_update_to_v2_from_v1(); $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();
}
// 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();
}
if ($oldversion < 2006050201) { return $ok;
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;
} }
?> ?>

View 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'; 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_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` # 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'; 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));

View file

@ -203,7 +203,7 @@ function hotpot_restore_details(&$restore, $status, &$xml, &$record) {
if (empty($record->details)) { if (empty($record->details)) {
$status = true; $status = true;
} else { } else {
unset($details); $details = new stdClass();
$details->attempt = $record->id; $details->attempt = $record->id;
$details->details = $record->details; $details->details = $record->details;
if (insert_record('hotpot_details', $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 // $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 // 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 // other parameters are explained in "hotpot_restore_record" below
$i = 0;
$i = 0; // index for $records_TAG
do { do {
unset($xml_records); unset($xml_records);
if ($records_TAG) { if ($records_TAG) {
@ -238,10 +239,8 @@ function hotpot_restore_records(&$restore, $status, &$xml, $table, $foreign_keys
$xml_records = &$xml; $xml_records = &$xml;
} }
} }
if (empty($xml_records)) { if (isset($xml_records)) {
// do nothing $ii = 0; // index for $record_TAG
} else {
$ii = 0;
do { do {
unset($xml_record); unset($xml_record);
if ($record_TAG) { if ($record_TAG) {
@ -253,9 +252,7 @@ function hotpot_restore_records(&$restore, $status, &$xml, $table, $foreign_keys
$xml_record = &$xml_records; $xml_record = &$xml_records;
} }
} }
if (empty($xml_record)) { if (isset($xml_record)) {
// do nothing
} else {
$status = hotpot_restore_record( $status = hotpot_restore_record(
$restore, $status, $xml_record, $table, $foreign_keys, $more_restore, $secondary_key $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. // 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 this field is specified, then the current record will only be added
// if the $record->$secondarykey value does not already exist in $table // 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); $TAGS = array_keys($xml);
foreach ($TAGS as $TAG) { foreach ($TAGS as $TAG) {
$value = $xml[$TAG][0]['#']; $value = $xml[$TAG][0]['#'];
@ -292,41 +298,65 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys,
$record->$tag = backup_todb($value); $record->$tag = backup_todb($value);
} }
} }
// update secondary keys, if any
$ok = true; $ok = true;
foreach ($foreign_keys as $key=>$value) { foreach ($foreign_keys as $key=>$value) {
if (is_numeric($value)) { if (is_numeric($value)) {
$record->$key = $value; $record->$key = $value;
} else { } else {
if (empty($record->$key)) { $key_table = $value;
$record->$key = NULL; $new_ids = array();
} else { if (isset($record->$key)) {
$key_table = $value;
$new_ids = array();
$old_ids = explode(',', $record->$key); $old_ids = explode(',', $record->$key);
foreach ($old_ids as $old_id) { foreach ($old_ids as $old_id) {
$key_record = backup_getid($restore->backup_unique_code, $key_table, $old_id); if (empty($old_id)) {
if ($key_record) { // do nothing
$new_ids[] = $key_record->new_id;
} else { } else {
// foreign key could not be updated $key_record = backup_getid($restore->backup_unique_code, $key_table, $old_id);
if (!defined('RESTORE_SILENTLY')) { if ($key_record) {
print "<ul><li><b>Warning:</b><br>Foreign key could not be updated:<br>"; $new_ids[] = $key_record->new_id;
print "'$key_table' record (old id=$old_id) is missing from backup data<br>"; } else {
print "'$table' record "; // foreign key could not be updated
if (isset($record->id)) { if (!defined('RESTORE_SILENTLY')) {
print "(old id=$record->id) "; 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 // check everything is OK so far
if ($ok && isset($record)) { if ($ok) {
// store old record id, if necessary // store old record id, if necessary
if (isset($record->id)) { if (isset($record->id)) {
$record->old_id = $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)) { if (empty($record->id)) {
// add the $record (and get new 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) // check $record was added (or found)
if (is_numeric($record->id)) { if (is_numeric($record->id)) {

View file

@ -3,9 +3,9 @@
/// Code fragment to define the version of hotpot /// Code fragment to define the version of hotpot
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php /// This fragment is called by moodle_needs_upgrading() and /admin/index.php
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
$module->version = 2006052200; // release date of this version (see note below) $module->version = 2006071600; // release date of this version (see note below)
$module->release = 'v2.1.20'; // human-friendly version name (used in mod/hotpot/lib.php) $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) $module->cron = 0; // period for cron to check this module (secs)
// interpretation of YYYYMMDDXY version numbers // interpretation of YYYYMMDDXY version numbers
// YYYY : year // YYYY : year
// MM : month // MM : month

View file

@ -318,30 +318,38 @@ function lesson_upgrade($oldversion) {
execute_sql('DROP TABLE '.$CFG->prefix.'lesson_essay', false); execute_sql('DROP TABLE '.$CFG->prefix.'lesson_essay', false);
// properly set the correct default values // properly set the correct default values
modify_database('', 'ALTER TABLE prefix_lesson table_column('lesson', 'activitylink', 'activitylink', 'integer', '8', '', '0');
ALTER COLUMN activitylink TYPE int8, table_column('lesson', 'dependency', 'dependency', 'integer', '8', '', '0');
ALTER COLUMN activitylink SET DEFAULT 0,
ALTER COLUMN dependency TYPE int8,
ALTER COLUMN dependency SET DEFAULT 0');
modify_database('', 'ALTER TABLE prefix_lesson_timer modify_database('', 'ALTER TABLE prefix_lesson_timer
ALTER COLUMN lessontime SET DEFAULT 0, ALTER COLUMN lessontime SET DEFAULT 0');
ALTER COLUMN lessonid SET DEFAULT 0, modify_database('', 'ALTER TABLE prefix_lesson_timer
ALTER COLUMN userid SET DEFAULT 0, 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'); ALTER COLUMN starttime SET DEFAULT 0');
modify_database('', 'ALTER TABLE prefix_lesson_branch modify_database('', 'ALTER TABLE prefix_lesson_branch
ALTER COLUMN lessonid SET DEFAULT 0, ALTER COLUMN lessonid SET DEFAULT 0');
ALTER COLUMN timeseen SET DEFAULT 0, modify_database('', 'ALTER TABLE prefix_lesson_branch
ALTER COLUMN userid SET DEFAULT 0, ALTER COLUMN timeseen SET DEFAULT 0');
ALTER COLUMN retry SET DEFAULT 0, modify_database('', 'ALTER TABLE prefix_lesson_branch
ALTER COLUMN pageid SET DEFAULT 0, 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'); ALTER COLUMN flag SET DEFAULT 0');
modify_database('', 'ALTER TABLE prefix_lesson_high_scores modify_database('', 'ALTER TABLE prefix_lesson_high_scores
ALTER COLUMN nickname SET DEFAULT \'\', ALTER COLUMN nickname SET DEFAULT \'\'');
ALTER COLUMN lessonid SET DEFAULT 0, modify_database('', 'ALTER TABLE prefix_lesson_high_scores
ALTER COLUMN gradeid SET DEFAULT 0, 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'); ALTER COLUMN userid SET DEFAULT 0');
} }

View file

@ -1306,6 +1306,12 @@
case LESSON_ENDOFBRANCH : case LESSON_ENDOFBRANCH :
echo get_string("endofbranch", "lesson"); echo get_string("endofbranch", "lesson");
break; break;
case LESSON_CLUSTER :
echo get_string("clustertitle", "lesson");
break;
case LESSON_ENDOFCLUSTER :
echo get_string("endofclustertitle", "lesson");
break;
} }
echo "</b></td></tr>\n"; echo "</b></td></tr>\n";
$i = 1; $i = 1;
@ -1436,7 +1442,11 @@
echo "$jumptitle</td></tr>\n"; echo "$jumptitle</td></tr>\n";
} }
} else { } 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 "<tr><td align=\"right\" width=\"20%\"><b>".get_string("score", "lesson")." $i:";
echo "</b></td><td width=\"80%\">\n"; echo "</b></td><td width=\"80%\">\n";
echo "$answer->score</td></tr>\n"; echo "$answer->score</td></tr>\n";