diff --git a/mod/lesson/db/mysql.php b/mod/lesson/db/mysql.php index c95120db24a..82f9567c9f8 100644 --- a/mod/lesson/db/mysql.php +++ b/mod/lesson/db/mysql.php @@ -40,7 +40,34 @@ function lesson_upgrade($oldversion) { table_column("lesson_answers", "", "flags", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); } - // CDC-FLAG + if ($oldversion < 2004060501) { + // matching questions need 2 records for responses and the + // 2 records must appear before the old ones. So, delete the old ones, + // create the 2 needed, then re-insert the old ones for each matching question. + if ($matchingquestions = get_records('lesson_pages', 'qtype', 5)) { // get our matching questions + foreach ($matchingquestions as $matchingquestion) { + if ($answers = get_records('lesson_answers', 'pageid', $matchingquestion->id)) { // get answers + if (delete_records('lesson_answers', 'pageid', $matchingquestion->id)) { // delete them + $time = time(); + // make our 2 response answers + $newanswer->lessonid = $matchingquestion->lessonid; + $newanswer->pageid = $matchingquestion->id; + $newanswer->timecreated = $time; + $newanswer->timemodified = 0; + insert_record('lesson_answers', $newanswer); + insert_record('lesson_answers', $newanswer); + // insert our old answers + foreach ($answers as $answer) { + $answer->timecreated = $time; + $answer->timemodified = 0; + insert_record('lesson_answers', $answer); + } + } + } + } + } + } + if ($oldversion < 2004072100) { execute_sql(" create table ".$CFG->prefix."lesson_high_scores ( id int(10) unsigned not null auto_increment, @@ -144,8 +171,6 @@ function lesson_upgrade($oldversion) { execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_default` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); } - // CDC-FLAG end - if ($oldversion < 2004111200) { execute_sql("ALTER TABLE {$CFG->prefix}lesson DROP INDEX course;",false); execute_sql("ALTER TABLE {$CFG->prefix}lesson_answers DROP INDEX lessonid;",false); diff --git a/mod/lesson/db/postgres7.php b/mod/lesson/db/postgres7.php index 0aa1dc32896..e71d173f328 100644 --- a/mod/lesson/db/postgres7.php +++ b/mod/lesson/db/postgres7.php @@ -39,7 +39,35 @@ function lesson_upgrade($oldversion) { if ($oldversion < 2004032700) { table_column("lesson_answers", "", "flags", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); } - // CDC-FLAG + + if ($oldversion < 2004060501) { + // matching questions need 2 records for responses and the + // 2 records must appear before the old ones. So, delete the old ones, + // create the 2 needed, then re-insert the old ones for each matching question. + if ($matchingquestions = get_records('lesson_pages', 'qtype', 5)) { // get our matching questions + foreach ($matchingquestions as $matchingquestion) { + if ($answers = get_records('lesson_answers', 'pageid', $matchingquestion->id)) { // get answers + if (delete_records('lesson_answers', 'pageid', $matchingquestion->id)) { // delete them + $time = time(); + // make our 2 response answers + $newanswer->lessonid = $matchingquestion->lessonid; + $newanswer->pageid = $matchingquestion->id; + $newanswer->timecreated = $time; + $newanswer->timemodified = 0; + insert_record('lesson_answers', $newanswer); + insert_record('lesson_answers', $newanswer); + // insert our old answers + foreach ($answers as $answer) { + $answer->timecreated = $time; + $answer->timemodified = 0; + insert_record('lesson_answers', $answer); + } + } + } + } + } + } + if ($oldversion < 2004072100) { execute_sql(" create table ".$CFG->prefix."lesson_high_scores ( id serial8 primary key, @@ -174,7 +202,7 @@ function lesson_upgrade($oldversion) { maxhighscores int8 NOT NULL default '0' )"); } - // CDC-FLAG end + if ($oldversion < 2004100400) { //execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_attempts` ADD `useranswer` text NOT NULL AFTER correct"); table_column('lesson_attempts', '', 'useranswer', 'text', '', '', '', 'NOT NULL', 'correct'); diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 32c9bd20e5a..164634ed5a1 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -54,7 +54,7 @@ if (!defined("LESSON_MULTICHOICE")) { // if you change the value of this (WHICH if (!defined("LESSON_RANDOM")) { define("LESSON_RANDOM", "4"); } -if (!defined("LESSON_MATCHING")) { // if you change the value of this (WHICH YOU SHOULDNT) then you need to change it in restorelib.php as well +if (!defined("LESSON_MATCHING")) { // if you change the value of this (WHICH YOU SHOULDNT) then you need to change it in restorelib.php, in mysql.php and postgres7.php as well define("LESSON_MATCHING", "5"); } if (!defined("LESSON_RANDOMSAMATCH")) { diff --git a/mod/lesson/restorelib.php b/mod/lesson/restorelib.php index e8dd3117cfd..04e5e86aaac 100644 --- a/mod/lesson/restorelib.php +++ b/mod/lesson/restorelib.php @@ -251,6 +251,24 @@ //Get the lesson_answers array (optional) if (isset($info['#']['ANSWERS']['0']['#']['ANSWER'])) { + // The following chunk of code is a fix for matching questions made + // pre moodle 1.5. Matching questions need two answer fields designated + // for correct and wrong responses before the rest of the answer fields. + if ($restore->backup_version <= 2004083124) { // Backup version for 1.4.5+ + if ($ismatching = get_record('lesson_pages', 'id', $pageid)) { // get the page we just inserted + if ($ismatching->qtype == 5) { // check to make sure it is a matching question + $time = time(); // this may need to be changed + // make our 2 response answers + $newanswer->lessonid = $lessonid; + $newanswer->pageid = $pageid; + $newanswer->timecreated = $time; + $newanswer->timemodified = 0; + insert_record('lesson_answers', $newanswer); + insert_record('lesson_answers', $newanswer); + } + } + } + $answers = $info['#']['ANSWERS']['0']['#']['ANSWER']; //Iterate over lesson_answers