From df103e82129a675dc07ec7f68acd785f3d014a4f Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 3 Mar 2003 17:43:13 +0000 Subject: [PATCH] Questions now have a defaultgrade column (which defaults to 1) ... this grade is used as the default grade when adding questions to a quiz. At the moment it's just so that some imported questions can have different defaults, but a field should be added to all question editing pages. --- mod/quiz/db/mysql.php | 4 ++++ mod/quiz/db/mysql.sql | 1 + mod/quiz/db/postgres7.php | 3 +++ mod/quiz/db/postgres7.sql | 1 + mod/quiz/edit.php | 8 +++++++- mod/quiz/format/missingword.php | 2 ++ mod/quiz/import.php | 4 +++- mod/quiz/lib.php | 2 -- mod/quiz/version.php | 2 +- 9 files changed, 22 insertions(+), 5 deletions(-) diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php index d9fe4baabb..3fbc7fc9f6 100644 --- a/mod/quiz/db/mysql.php +++ b/mod/quiz/db/mysql.php @@ -50,6 +50,10 @@ function quiz_upgrade($oldversion) { );"); } + if ($oldversion < 2003030302) { + table_column("quiz_questions", "", "defaultgrade", "INTEGER", "6", "UNSIGNED", "1", "NOT NULL", "image"); + } + return true; } diff --git a/mod/quiz/db/mysql.sql b/mod/quiz/db/mysql.sql index 0e35e92f58..f85d83838a 100644 --- a/mod/quiz/db/mysql.sql +++ b/mod/quiz/db/mysql.sql @@ -143,6 +143,7 @@ CREATE TABLE `prefix_quiz_questions` ( `name` varchar(255) NOT NULL default '', `questiontext` text NOT NULL, `image` varchar(255) NOT NULL default '', + `defaultgrade` INT UNSIGNED DEFAULT '1' NOT NULL, `qtype` smallint(6) NOT NULL default '0', PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT='The quiz questions themselves'; diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index 4a26f8ee9c..1e424afb79 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -23,6 +23,9 @@ function quiz_upgrade($oldversion) { choose integer NOT NULL default '4', );"); } + if ($oldversion < 2003030302) { + table_column("quiz_questions", "", "defaultgrade", "INTEGER", "6", "UNSIGNED", "1", "NOT NULL", "image"); + } return true; } diff --git a/mod/quiz/db/postgres7.sql b/mod/quiz/db/postgres7.sql index 3b140b1fdb..7d49ec4a5e 100644 --- a/mod/quiz/db/postgres7.sql +++ b/mod/quiz/db/postgres7.sql @@ -124,6 +124,7 @@ CREATE TABLE prefix_quiz_questions ( name varchar(255) NOT NULL default '', questiontext text NOT NULL default '', image varchar(255) NOT NULL default '', + defaultgrade integer NOT NULL default '1' qtype integer NOT NULL default '0' ); # -------------------------------------------------------- diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 1699981556..c2ebdd9270 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -91,7 +91,13 @@ } } $questions[] = $key; - $modform->grades[$key] = QUIZ_DEFAULT_SCORE; + + $questionrecord = get_record("quiz_questions", "id", $key); + if (!empty($questionrecord->defaultgrade)) { + $modform->grades[$key] = $questionrecord->defaultgrade; + } else { + $modform->grades[$key] = 1; + } } } if (!empty($questions)) { diff --git a/mod/quiz/format/missingword.php b/mod/quiz/format/missingword.php index b10cdac0f0..92d648a1da 100644 --- a/mod/quiz/format/missingword.php +++ b/mod/quiz/format/missingword.php @@ -78,6 +78,7 @@ class quiz_file_format extends quiz_default_format { $question->feedback[] = ""; $question->usecase = 0; // Ignore case + $question->defaultgrade = 1; $question->image = ""; // No images with this format return $question; @@ -97,6 +98,7 @@ class quiz_file_format extends quiz_default_format { $question->feedback[$key] = ""; } + $question->defaultgrade = 1; $question->single = 1; // Only one answer is allowed $question->image = ""; // No images with this format return $question; diff --git a/mod/quiz/import.php b/mod/quiz/import.php index 169cdc50c6..f2eb618328 100644 --- a/mod/quiz/import.php +++ b/mod/quiz/import.php @@ -86,17 +86,19 @@ if (!empty($form->createrandom)) { /// Create a number of random questions + $rm->choose = 4; /// Always 4, for now. $rm->category = $category->id; $rm->questiontext = get_string("randommatchintro", "quiz"); $rm->image = ""; $rm->qtype = RANDOMMATCH; - $rm->choose = 4; /// Always 4, for now. + $rm->defaultgrade = $rm->choose; echo "
"; for ($i=1; $i<=$form->createrandom; $i++) { $rm->name = get_string("randommatch", "quiz") . " $i ($rm->choose $strquestions)"; + $db->debug = true; if (!$rm->id = insert_record("quiz_questions", $rm)) { error("Could not insert new question!"); } diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 560e36dc0b..8edeffc952 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -32,8 +32,6 @@ $QUIZ_FILE_FORMAT = array ( "custom" => get_string("custom", "quiz"), define("QUIZ_PICTURE_DEFAULT_HEIGHT", "200"); -define("QUIZ_DEFAULT_SCORE", "1"); - /// FUNCTIONS /////////////////////////////////////////////////////////////////// function quiz_add_instance($quiz) { diff --git a/mod/quiz/version.php b/mod/quiz/version.php index 1eb49a5c2e..d5ea2d9938 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -5,7 +5,7 @@ // This fragment is called by moodle_needs_upgrading() and /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2003022303; // The (date) version of this module +$module->version = 2003030302; // The (date) version of this module $module->cron = 0; // How often should cron check this module (seconds)? ?> -- 2.39.5