mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
I think I have a solution for the problems with matching question type and upgrading moodle from 1.4.x to 1.5+.
View bug 3468 and this forum post for more information: http://moodle.org/mod/forum/discuss.php?d=27354
This commit is contained in:
parent
67316e5b44
commit
afbc9cbdc3
4 changed files with 77 additions and 6 deletions
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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")) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue