From 55190d7e2c2defe7bed6e22c51dd48bcd8e3d4e2 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 9 Jun 2011 19:27:36 +0100 Subject: [PATCH] MDL-20538 get rid of badly name-spaced constants from lib/questionlib.php. Unfortunately, they are used all over the import/export code, so I cannot eliminate them completely. However, I was able to move them out of the core library. --- lib/questionlib.php | 16 ------------- mod/lesson/format.php | 21 ++++++++++++++++ mod/quiz/db/upgradelib.php | 2 +- question/format.php | 25 +++++++++++++++++++- question/type/randomsamatch/questiontype.php | 4 ++-- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/lib/questionlib.php b/lib/questionlib.php index 8371f3bc3e3..92c65664c2b 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -41,22 +41,6 @@ require_once($CFG->dirroot . '/question/type/questiontypebase.php'); /// CONSTANTS /////////////////////////////////// -/**#@+ - * The core question types. - */ -define("SHORTANSWER", "shortanswer"); -define("TRUEFALSE", "truefalse"); -define("MULTICHOICE", "multichoice"); -define("RANDOM", "random"); -define("MATCH", "match"); -define("RANDOMSAMATCH", "randomsamatch"); -define("DESCRIPTION", "description"); -define("NUMERICAL", "numerical"); -define("MULTIANSWER", "multianswer"); -define("CALCULATED", "calculated"); -define("ESSAY", "essay"); -/**#@-*/ - /** * Constant determines the number of answer boxes supplied in the editing * form for multiple choice and similar question types. diff --git a/mod/lesson/format.php b/mod/lesson/format.php index 5a2ea0c8798..8fded7b07bc 100644 --- a/mod/lesson/format.php +++ b/mod/lesson/format.php @@ -29,6 +29,27 @@ defined('MOODLE_INTERNAL') || die(); +/**#@+ + * The core question types. + * + * These used to be in lib/questionlib.php, but are being deprecated. Copying them + * here to keep this code working for now. + */ +if (!defined('SHORTANSWER')) { + define("SHORTANSWER", "shortanswer"); + define("TRUEFALSE", "truefalse"); + define("MULTICHOICE", "multichoice"); + define("RANDOM", "random"); + define("MATCH", "match"); + define("RANDOMSAMATCH", "randomsamatch"); + define("DESCRIPTION", "description"); + define("NUMERICAL", "numerical"); + define("MULTIANSWER", "multianswer"); + define("CALCULATED", "calculated"); + define("ESSAY", "essay"); +} +/**#@-*/ + /** * Given some question info and some data about the the answers * this function parses, organises and saves the question diff --git a/mod/quiz/db/upgradelib.php b/mod/quiz/db/upgradelib.php index bc2874dda0a..0b458efb4e8 100644 --- a/mod/quiz/db/upgradelib.php +++ b/mod/quiz/db/upgradelib.php @@ -49,7 +49,7 @@ function quiz_upgrade_very_old_question_sessions($attempt) { // newgraded pointing to this state. // Actually we only do this for states whose question is actually listed in $attempt->layout. // We do not do it for states associated to wrapped questions like for example the questions - // used by a RANDOM question + // used by a random question $session = new stdClass(); $session->attemptid = $attempt->uniqueid; $session->sumpenalty = 0; diff --git a/question/format.php b/question/format.php index 663e9176baf..8cdbfbdbaaf 100644 --- a/question/format.php +++ b/question/format.php @@ -27,6 +27,29 @@ defined('MOODLE_INTERNAL') || die(); +/**#@+ + * The core question types. + * + * These used to be in lib/questionlib.php, but are being deprecated. Copying + * them here to keep the import/export code working for now (there are 135 + * references to these constants which I don't want to try to fix at the moment.) + */ +if (!defined('SHORTANSWER')) { + define("SHORTANSWER", "shortanswer"); + define("TRUEFALSE", "truefalse"); + define("MULTICHOICE", "multichoice"); + define("RANDOM", "random"); + define("MATCH", "match"); + define("RANDOMSAMATCH", "randomsamatch"); + define("DESCRIPTION", "description"); + define("NUMERICAL", "numerical"); + define("MULTIANSWER", "multianswer"); + define("CALCULATED", "calculated"); + define("ESSAY", "essay"); +} +/**#@-*/ + + /** * Base class for question import and export formats. * @@ -697,7 +720,7 @@ class qformat_default { } // do not export random questions - if ($question->qtype==RANDOM) { + if ($question->qtype == 'random') { continue; } diff --git a/question/type/randomsamatch/questiontype.php b/question/type/randomsamatch/questiontype.php index b88006bf149..74e1dcbc923 100644 --- a/question/type/randomsamatch/questiontype.php +++ b/question/type/randomsamatch/questiontype.php @@ -116,7 +116,7 @@ class qtype_randomsamatch extends question_type { available for this question, therefore it is not available in this quiz. Please inform your teacher."; // Treat this as a description from this point on - $question->qtype = DESCRIPTION; + $question->qtype = 'description'; return true; } @@ -174,7 +174,7 @@ class qtype_randomsamatch extends question_type { available for this question, therefore it is not available in this quiz. Please inform your teacher."; // Treat this as a description from this point on - $question->qtype = DESCRIPTION; + $question->qtype = 'description'; } else { $responses = explode(',', $state->responses['']); $responses = array_map(create_function('$val',