From 7c4127efadd33abdb20301643e36f5650e33c9b9 Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Sat, 11 Feb 2006 21:07:08 +0000 Subject: [PATCH] Put the default grade option onto question edit forms, see http://moodle.org/mod/forum/discuss.php?d=39371#181767 --- mod/quiz/db/mysql.php | 6 ++++++ mod/quiz/db/postgres7.php | 7 +++++++ mod/quiz/editlib.php | 9 ++------- mod/quiz/preview.php | 13 ++++++++----- mod/quiz/questiontypes/calculated/calculated.html | 8 ++++++++ mod/quiz/questiontypes/essay/essay.html | 8 ++++++++ mod/quiz/questiontypes/match/match.html | 8 ++++++++ mod/quiz/questiontypes/multichoice/multichoice.html | 8 ++++++++ mod/quiz/questiontypes/numerical/numerical.html | 8 ++++++++ .../questiontypes/randomsamatch/questiontype.php | 6 ++---- .../questiontypes/randomsamatch/randomsamatch.html | 8 ++++++++ mod/quiz/questiontypes/shortanswer/shortanswer.html | 8 ++++++++ mod/quiz/questiontypes/truefalse/truefalse.html | 8 ++++++++ mod/quiz/version.php | 2 +- 14 files changed, 90 insertions(+), 17 deletions(-) diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php index c90185c12d6..30b92530a36 100644 --- a/mod/quiz/db/mysql.php +++ b/mod/quiz/db/mysql.php @@ -877,6 +877,12 @@ function quiz_upgrade($oldversion) { table_column('quiz', '', 'delay2', 'integer', '10', 'unsigned', '0', 'not null', 'delay1'); } + if ($oldversion < 2006021101) { + // set defaultgrade field properly (probably not necessary, but better make sure) + execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '1' WHERE defaultgrade = '0'", false); + execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '0' WHERE qtype = '".DESCRIPTION."'", false); + } + return true; } diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index f2be1fad86f..026a677dc27 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -972,6 +972,13 @@ function quiz_upgrade($oldversion) { table_column("quiz", "", "delay1", "INTEGER", "10", "UNSIGNED", "0", "NOT NULL", "popup"); table_column("quiz", "", "delay2", "INTEGER", "10", "UNSIGNED", "0", "NOT NULL", "delay1"); } + + if ($oldversion < 2006021101) { + // set defaultgrade field properly (probably not necessary, but better make sure) + execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '1' WHERE defaultgrade = '0'", false); + execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '0' WHERE qtype = '".DESCRIPTION."'", false); + } + return true; } diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index fa33cfb1d7d..8e8bf21a778 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -132,14 +132,9 @@ function quiz_add_quiz_question($id, &$modform) { // update question grades $questionrecord = get_record("quiz_questions", "id", $id); - if (!empty($questionrecord->defaultgrade)) { - $modform->grades[$id] = $questionrecord->defaultgrade; - } else if ($questionrecord->qtype == DESCRIPTION){ - $modform->grades[$id] = 0; - } else { - $modform->grades[$id] = 1; - } + $modform->grades[$id] = $questionrecord->defaultgrade; quiz_update_question_instance($modform->grades[$id], $id, $modform->instance); + return true; } diff --git a/mod/quiz/preview.php b/mod/quiz/preview.php index 5480df4ac1e..05cb5a38bee 100644 --- a/mod/quiz/preview.php +++ b/mod/quiz/preview.php @@ -75,15 +75,18 @@ error("Quiz id $quizid does not exist"); } - $quiz->id = 0; // just for safety - $quiz->questions = $id; - // Load the question information if (!$questions = get_records('quiz_questions', 'id', $id)) { error('Could not load question'); } - $questions[$id]->quiz = 0; - $questions[$id]->maxgrade = 1; + if ($maxgrade = get_field('quiz_question_instances', 'grade', 'quiz', $quiz->id, 'question', $id)) { + $questions[$id]->maxgrade = $maxgrade; + } else { + $questions[$id]->maxgrade = $questions[$id]->defaultgrade; + } + + $quiz->id = 0; // just for safety + $quiz->questions = $id; if (!$category = get_record("quiz_categories", "id", $questions[$id]->category)) { error("This question doesn't belong to a valid category!"); diff --git a/mod/quiz/questiontypes/calculated/calculated.html b/mod/quiz/questiontypes/calculated/calculated.html index cde67ca2aa3..e8b6a5fed9f 100644 --- a/mod/quiz/questiontypes/calculated/calculated.html +++ b/mod/quiz/questiontypes/calculated/calculated.html @@ -64,6 +64,14 @@ ?> + + : + + " /> + + + + : diff --git a/mod/quiz/questiontypes/essay/essay.html b/mod/quiz/questiontypes/essay/essay.html index de30640ba18..478267f019b 100644 --- a/mod/quiz/questiontypes/essay/essay.html +++ b/mod/quiz/questiontypes/essay/essay.html @@ -73,6 +73,14 @@ ?> + + : + + " /> + + + + : diff --git a/mod/quiz/questiontypes/match/match.html b/mod/quiz/questiontypes/match/match.html index 95a08fb5174..749b03619b4 100644 --- a/mod/quiz/questiontypes/match/match.html +++ b/mod/quiz/questiontypes/match/match.html @@ -62,6 +62,14 @@ ?> + + : + + " /> + + + + : diff --git a/mod/quiz/questiontypes/multichoice/multichoice.html b/mod/quiz/questiontypes/multichoice/multichoice.html index be6209a27d8..dd692b9c3f6 100644 --- a/mod/quiz/questiontypes/multichoice/multichoice.html +++ b/mod/quiz/questiontypes/multichoice/multichoice.html @@ -70,6 +70,14 @@ ?> + + : + + " /> + + + + : diff --git a/mod/quiz/questiontypes/numerical/numerical.html b/mod/quiz/questiontypes/numerical/numerical.html index 1c6a861d9db..7147cdffb61 100644 --- a/mod/quiz/questiontypes/numerical/numerical.html +++ b/mod/quiz/questiontypes/numerical/numerical.html @@ -64,6 +64,14 @@ ?> + + : + + " /> + + + + : diff --git a/mod/quiz/questiontypes/randomsamatch/questiontype.php b/mod/quiz/questiontypes/randomsamatch/questiontype.php index 5a25ff79ab6..83c9a059888 100644 --- a/mod/quiz/questiontypes/randomsamatch/questiontype.php +++ b/mod/quiz/questiontypes/randomsamatch/questiontype.php @@ -4,10 +4,8 @@ /// RANDOMSAMATCH /// ///////////////////// -/// The use of this question type together with the -/// question type RANDOM within the same quiz can cause -/// a shortanswer question to appear in a RANDOM question -/// as well as one of the matcher questions in a question of this type +/// TODO: Make sure short answer questions chosen by a randomsamatch question +/// can not also be used by a random question /// QUESTION TYPE CLASS ////////////////// class quiz_randomsamatch_qtype extends quiz_match_qtype { diff --git a/mod/quiz/questiontypes/randomsamatch/randomsamatch.html b/mod/quiz/questiontypes/randomsamatch/randomsamatch.html index e8de9fe5a73..9b62df17507 100644 --- a/mod/quiz/questiontypes/randomsamatch/randomsamatch.html +++ b/mod/quiz/questiontypes/randomsamatch/randomsamatch.html @@ -58,6 +58,14 @@ ?> + + : + + " /> + + + + : diff --git a/mod/quiz/questiontypes/shortanswer/shortanswer.html b/mod/quiz/questiontypes/shortanswer/shortanswer.html index 1aef9545ff2..8afccca5abe 100644 --- a/mod/quiz/questiontypes/shortanswer/shortanswer.html +++ b/mod/quiz/questiontypes/shortanswer/shortanswer.html @@ -73,6 +73,14 @@ ?> + + : + + " /> + + + + : diff --git a/mod/quiz/questiontypes/truefalse/truefalse.html b/mod/quiz/questiontypes/truefalse/truefalse.html index 05714706655..0d00ab5b33f 100644 --- a/mod/quiz/questiontypes/truefalse/truefalse.html +++ b/mod/quiz/questiontypes/truefalse/truefalse.html @@ -62,6 +62,14 @@ ?> + + : + + " /> + + + + : diff --git a/mod/quiz/version.php b/mod/quiz/version.php index a13ee7bd8a6..952ae2cd0fe 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 = 2006020801; // The (date) version of this module +$module->version = 2006021102; // The (date) version of this module $module->requires = 2005021600; // Requires this Moodle version $module->cron = 0; // How often should cron check this module (seconds)?