From dfa47f965c85c8083d8d866b04a9f97304cd5591 Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Wed, 22 Mar 2006 13:51:25 +0000 Subject: [PATCH] Cleanup: don't use questiontype constants within questiontypes --- .../questiontypes/calculated/editquestion.php | 2 +- .../questiontypes/calculated/questiontype.php | 7 ++-- .../description/questiontype.php | 6 ++-- question/questiontypes/essay/questiontype.php | 7 ++-- question/questiontypes/match/questiontype.php | 5 ++- .../multianswer/editquestion.php | 6 ++-- .../multianswer/questiontype.php | 33 +++++++++---------- .../multichoice/questiontype.php | 5 ++- .../questiontypes/numerical/questiontype.php | 5 ++- question/questiontypes/questiontype.php | 2 +- .../questiontypes/random/questiontype.php | 6 ++-- .../randomsamatch/editquestion.php | 2 +- .../randomsamatch/questiontype.php | 9 +++-- .../shortanswer/questiontype.php | 7 ++-- .../questiontypes/truefalse/questiontype.php | 5 ++- 15 files changed, 49 insertions(+), 58 deletions(-) diff --git a/question/questiontypes/calculated/editquestion.php b/question/questiontypes/calculated/editquestion.php index 7e87a8b58e..0c4e3c7866 100644 --- a/question/questiontypes/calculated/editquestion.php +++ b/question/questiontypes/calculated/editquestion.php @@ -1,7 +1,7 @@ substitute_variables($formula, $individualdata); + $answer = $QTYPES['calculated']->substitute_variables($formula, $individualdata); if ('1' == $answerformat) { /* Answer is to have $answerlength decimals */ /*** Adjust to the correct number of decimals ***/ diff --git a/question/questiontypes/description/questiontype.php b/question/questiontypes/description/questiontype.php index c8a4141195..d8921d54d7 100644 --- a/question/questiontypes/description/questiontype.php +++ b/question/questiontypes/description/questiontype.php @@ -7,7 +7,7 @@ /// QUESTION TYPE CLASS ////////////////// // -// The question type DESCRIPTION is not really a question type +// The question type 'description' is not really a question type // and it therefore often sticks to some kind of odd behaviour // @@ -70,8 +70,8 @@ class quiz_description_qtype extends default_questiontype { //// INITIATION - Without this line the question type is not in use... /// ////////////////////////////////////////////////////////////////////////// // define("DESCRIPTION", "7"); // already defined in questionlib.php -$QTYPES[DESCRIPTION]= new quiz_description_qtype(); +$QTYPES['description']= new quiz_description_qtype(); // The following adds the questiontype to the menu of types shown to teachers -$QTYPE_MENU[DESCRIPTION] = get_string("description", "quiz"); +$QTYPE_MENU['description'] = get_string("description", "quiz"); ?> diff --git a/question/questiontypes/essay/questiontype.php b/question/questiontypes/essay/questiontype.php index dc0d6d3f2a..19fe7b4e8a 100644 --- a/question/questiontypes/essay/questiontype.php +++ b/question/questiontypes/essay/questiontype.php @@ -274,7 +274,7 @@ class question_essay_qtype extends default_questiontype { " {$CFG->prefix}quiz_question_instances i". " WHERE i.quiz = '$cmoptions->id' AND q.id = i.question". " AND q.id IN ($questionlist)". - " AND q.qtype = '".ESSAY."'". + " AND q.qtype = '".'essay'."'". " ORDER BY q.name"; if (empty($attemptid)) { @@ -412,9 +412,8 @@ class question_essay_qtype extends default_questiontype { ////////////////////////////////////////////////////////////////////////// //// INITIATION - Without this line the question type is not in use... /// ////////////////////////////////////////////////////////////////////////// -// define("ESSAY", "12"); // already defined in questionlib.php -$QTYPES[ESSAY] = new question_essay_qtype(); +$QTYPES['essay'] = new question_essay_qtype(); // The following adds the questiontype to the menu of types shown to teachers -$QTYPE_MENU[ESSAY] = get_string("essay", "quiz"); +$QTYPE_MENU['essay'] = get_string("essay", "quiz"); ?> diff --git a/question/questiontypes/match/questiontype.php b/question/questiontypes/match/questiontype.php index 5035ba92dd..32a3ad45c5 100644 --- a/question/questiontypes/match/questiontype.php +++ b/question/questiontypes/match/questiontype.php @@ -532,9 +532,8 @@ class question_match_qtype extends default_questiontype { ////////////////////////////////////////////////////////////////////////// //// INITIATION - Without this line the question type is not in use... /// ////////////////////////////////////////////////////////////////////////// -// define("MATCH", "5"); // already defined in questionlib.php -$QTYPES[MATCH]= new question_match_qtype(); +$QTYPES['match']= new question_match_qtype(); // The following adds the questiontype to the menu of types shown to teachers -$QTYPE_MENU[MATCH] = get_string("match", "quiz"); +$QTYPE_MENU['match'] = get_string("match", "quiz"); ?> diff --git a/question/questiontypes/multianswer/editquestion.php b/question/questiontypes/multianswer/editquestion.php index 8856cc5b89..42dbdf2072 100644 --- a/question/questiontypes/multianswer/editquestion.php +++ b/question/questiontypes/multianswer/editquestion.php @@ -9,13 +9,13 @@ if (empty($wrapped->questiontext)) { $parsableanswerdef = '{' . $wrapped->defaultgrade . ':'; switch ($wrapped->qtype) { - case MULTICHOICE: + case 'multichoice': $parsableanswerdef .= 'MULTICHOICE:'; break; - case SHORTANSWER: + case 'shortanswer': $parsableanswerdef .= 'SHORTANSWER:'; break; - case NUMERICAL: + case 'numerical': $parsableanswerdef .= 'NUMERICAL:'; break; default: diff --git a/question/questiontypes/multianswer/questiontype.php b/question/questiontypes/multianswer/questiontype.php index c37ea7de28..f34308130e 100644 --- a/question/questiontypes/multianswer/questiontype.php +++ b/question/questiontypes/multianswer/questiontype.php @@ -7,9 +7,9 @@ /// /// The multianswer question type is special in that it /// depends on a few other question types, i.e. -/// MULTICHOICE, SHORTANSWER and NUMERICAL. +/// 'multichoice', 'shortanswer' and 'numerical'. /// These question types have got a few special features that -/// makes them useable by the MULTIANSWER question type +/// makes them useable by the 'multianswer' question type /// /// QUESTION TYPE CLASS ////////////////// @@ -233,7 +233,7 @@ class quiz_embedded_cloze_qtype extends default_questiontype { if ($options->feedback) { $chosenanswer = null; switch ($wrapped->qtype) { - case NUMERICAL: + case 'numerical': $testedstate = clone($state); $testedstate->responses[''] = $response; $raw_grade = 0; @@ -247,7 +247,7 @@ class quiz_embedded_cloze_qtype extends default_questiontype { } } break; - case SHORTANSWER: + case 'shortanswer': $testedstate = clone($state); $testedstate->responses[''] = $response; $teststate = clone($state); @@ -263,7 +263,7 @@ class quiz_embedded_cloze_qtype extends default_questiontype { } } break; - case MULTICHOICE: + case 'multichoice': if (isset($answers[$response])) { $chosenanswer = clone($answers[$response]); } @@ -307,12 +307,12 @@ class quiz_embedded_cloze_qtype extends default_questiontype { // Print the input control switch ($wrapped->qtype) { - case SHORTANSWER: - case NUMERICAL: + case 'shortanswer': + case 'numerical': echo " "; break; - case MULTICHOICE: + case 'multichoice': $outputoptions = ''; // Default empty option foreach ($answers as $mcanswer) { $selected = $response == $mcanswer->id @@ -555,7 +555,7 @@ class quiz_embedded_cloze_qtype extends default_questiontype { error("Can't find the subquestion $wrappedquestionid that is used as part $seqnum in cloze question $state->question"); } // For multichoice question we need to recode the answer - if ($answer and $wrappedquestion->qtype == MULTICHOICE) { + if ($answer and $wrappedquestion->qtype == 'multichoice') { //The answer is an answer_id, look for it in backup_ids if (!$ans = backup_getid($restore->backup_unique_code,"question_answers",$answer)) { echo 'Could not recode cloze multichoice answer '.$answer.'
'; @@ -583,15 +583,14 @@ class quiz_embedded_cloze_qtype extends default_questiontype { ////////////////////////////////////////////////////////////////////////// //// INITIATION - Without this line the question type is not in use... /// ////////////////////////////////////////////////////////////////////////// -// define("MULTIANSWER", "9"); // already defined in questionlib.php -$QTYPES[MULTIANSWER]= new quiz_embedded_cloze_qtype(); +$QTYPES['multianswer']= new quiz_embedded_cloze_qtype(); // The following adds the questiontype to the menu of types shown to teachers -$QTYPE_MENU[MULTIANSWER] = get_string("multianswer", "quiz"); +$QTYPE_MENU['multianswer'] = get_string("multianswer", "quiz"); ///////////////////////////////////////////////////////////// //// ADDITIONAL FUNCTIONS //// The functions below deal exclusivly with editing -//// of questions with question type MULTIANSWER. +//// of questions with question type 'multianswer'. //// Therefore they are kept in this file. //// They are not in the class as they are not //// likely to be subject for overriding. @@ -688,7 +687,7 @@ function quiz_qtype_multianswer_extract_question($text) { //////////////////////////////////////// $question = new stdClass; - $question->qtype = MULTIANSWER; + $question->qtype = 'multianswer'; $question->questiontext = $text; $question->options->questions = array(); $question->defaultgrade = 0; // Will be increased for each answer norm @@ -700,14 +699,14 @@ function quiz_qtype_multianswer_extract_question($text) { $wrapped->defaultgrade = $answerregs[ANSWER_REGEX_NORM] or $wrapped->defaultgrade = '1'; if (!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_NUMERICAL])) { - $wrapped->qtype = NUMERICAL; + $wrapped->qtype = 'numerical'; $wrapped->multiplier = array(); $wrapped->units = array(); } else if(!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_SHORTANSWER])) { - $wrapped->qtype = SHORTANSWER; + $wrapped->qtype = 'shortanswer'; $wrapped->usecase = 0; } else if(!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE])) { - $wrapped->qtype = MULTICHOICE; + $wrapped->qtype = 'multichoice'; $wrapped->single = 1; } else { error("Cannot identify qtype $answerregs[2]"); diff --git a/question/questiontypes/multichoice/questiontype.php b/question/questiontypes/multichoice/questiontype.php index b63a97b484..130c0f936e 100644 --- a/question/questiontypes/multichoice/questiontype.php +++ b/question/questiontypes/multichoice/questiontype.php @@ -514,9 +514,8 @@ class question_multichoice_qtype extends default_questiontype { ////////////////////////////////////////////////////////////////////////// //// INITIATION - Without this line the question type is not in use... /// ////////////////////////////////////////////////////////////////////////// -// define("MULTICHOICE", "3"); // already defined in questionlib.php -$QTYPES[MULTICHOICE]= new question_multichoice_qtype(); +$QTYPES['multichoice']= new question_multichoice_qtype(); // The following adds the questiontype to the menu of types shown to teachers -$QTYPE_MENU[MULTICHOICE] = get_string("multichoice", "quiz"); +$QTYPE_MENU['multichoice'] = get_string("multichoice", "quiz"); ?> diff --git a/question/questiontypes/numerical/questiontype.php b/question/questiontypes/numerical/questiontype.php index 6231c205c2..74c34d9dd1 100644 --- a/question/questiontypes/numerical/questiontype.php +++ b/question/questiontypes/numerical/questiontype.php @@ -497,9 +497,8 @@ class question_numerical_qtype extends question_shortanswer_qtype { ////////////////////////////////////////////////////////////////////////// //// INITIATION - Without this line the question type is not in use... /// ////////////////////////////////////////////////////////////////////////// -// define("NUMERICAL", "8"); // already defined in questionlib.php -$QTYPES[NUMERICAL]= new question_numerical_qtype(); +$QTYPES['numerical']= new question_numerical_qtype(); // The following adds the questiontype to the menu of types shown to teachers -$QTYPE_MENU[NUMERICAL] = get_string("numerical", "quiz"); +$QTYPE_MENU['numerical'] = get_string("numerical", "quiz"); ?> diff --git a/question/questiontypes/questiontype.php b/question/questiontypes/questiontype.php index 4822cb1743..3ea06b474f 100644 --- a/question/questiontypes/questiontype.php +++ b/question/questiontypes/questiontype.php @@ -195,7 +195,7 @@ class default_questiontype { * * This function returns the number of question numbers to be assigned * to the question. Most question types will have length one; they will be - * assigned one number. The DESCRIPTION type, however does not use up a + * assigned one number. The 'description' type, however does not use up a * number and so has a length of zero. Other question types may wish to * handle a bundle of questions and hence return a number greater than one. * @return integer The number of question numbers which should be diff --git a/question/questiontypes/random/questiontype.php b/question/questiontypes/random/questiontype.php index 77e8e7547e..71c48dc6f1 100644 --- a/question/questiontypes/random/questiontype.php +++ b/question/questiontypes/random/questiontype.php @@ -7,7 +7,7 @@ /// QUESTION TYPE CLASS ////////////////// class quiz_random_qtype extends default_questiontype { - var $excludedtypes = array(RANDOM, RANDOMSAMATCH, ESSAY, DESCRIPTION); + var $excludedtypes = array('random', 'randomsamatch', 'essay', 'description'); // Carries questions available as randoms sorted by category // This array is used when needed only @@ -87,7 +87,7 @@ class quiz_random_qtype extends default_questiontype { } $question->questiontext = ''. get_string('toomanyrandom', 'quiz'). ''; - $question->qtype = DESCRIPTION; + $question->qtype = 'description'; $state->responses = array('' => ''); return true; } @@ -115,7 +115,7 @@ class quiz_random_qtype extends default_questiontype { // This is the case if there weren't enough questions available in the category. $question->questiontext = ''. get_string('toomanyrandom', 'quiz'). ''; - $question->qtype = DESCRIPTION; + $question->qtype = 'description'; return true; } // this must be an old-style state which stores only the id for the wrapped question diff --git a/question/questiontypes/randomsamatch/editquestion.php b/question/questiontypes/randomsamatch/editquestion.php index 4a039dce92..ee53a95d78 100644 --- a/question/questiontypes/randomsamatch/editquestion.php +++ b/question/questiontypes/randomsamatch/editquestion.php @@ -5,7 +5,7 @@ $options->choose = ""; $options->shuffleanswers = 1; } - $saquestions = $QTYPES[RANDOMSAMATCH]->get_sa_candidates($category->id); + $saquestions = $QTYPES['randomsamatch']->get_sa_candidates($category->id); $numberavailable = count($saquestions); unset($saquestions); diff --git a/question/questiontypes/randomsamatch/questiontype.php b/question/questiontypes/randomsamatch/questiontype.php index 25ee59fc40..d3d214a6a0 100644 --- a/question/questiontypes/randomsamatch/questiontype.php +++ b/question/questiontypes/randomsamatch/questiontype.php @@ -9,7 +9,7 @@ /// QUESTION TYPE CLASS ////////////////// class question_randomsamatch_qtype extends question_match_qtype { -/// Extends MATCH as there are quite a few simularities... +/// Extends 'match' as there are quite a few simularities... function name() { return 'randomsamatch'; @@ -235,7 +235,7 @@ class question_randomsamatch_qtype extends question_match_qtype { function get_sa_candidates($categorylist, $questionsinuse=0) { return get_records_select('question', - "qtype = '".SHORTANSWER."' " . + "qtype = '".'shortanswer'."' " . "AND category IN ($categorylist) " . "AND parent = '0' " . "AND hidden = '0'" . @@ -356,9 +356,8 @@ class question_randomsamatch_qtype extends question_match_qtype { ////////////////////////////////////////////////////////////////////////// //// INITIATION - Without this line the question type is not in use... /// ////////////////////////////////////////////////////////////////////////// -// define("RANDOMSAMATCH", "6"); // already defined in questionlib.php -$QTYPES[RANDOMSAMATCH]= new question_randomsamatch_qtype(); +$QTYPES['randomsamatch']= new question_randomsamatch_qtype(); // The following adds the questiontype to the menu of types shown to teachers -$QTYPE_MENU[RANDOMSAMATCH] = get_string("randomsamatch", "quiz"); +$QTYPE_MENU['randomsamatch'] = get_string("randomsamatch", "quiz"); ?> diff --git a/question/questiontypes/shortanswer/questiontype.php b/question/questiontypes/shortanswer/questiontype.php index c6c8c86681..27543aa659 100644 --- a/question/questiontypes/shortanswer/questiontype.php +++ b/question/questiontypes/shortanswer/questiontype.php @@ -119,7 +119,7 @@ class question_shortanswer_qtype extends default_questiontype { function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { global $CFG; - /// This implementation is also used by question type NUMERICAL + /// This implementation is also used by question type 'numerical' $answers = &$question->options->answers; $correctanswers = $this->get_correct_responses($question, $state); $readonly = empty($options->readonly) ? '' : 'readonly="readonly"'; @@ -345,9 +345,8 @@ class question_shortanswer_qtype extends default_questiontype { ////////////////////////////////////////////////////////////////////////// //// INITIATION - Without this line the question type is not in use... /// ////////////////////////////////////////////////////////////////////////// -// define("SHORTANSWER", "1"); // already defined in questionlib.php -$QTYPES[SHORTANSWER]= new question_shortanswer_qtype(); +$QTYPES['shortanswer']= new question_shortanswer_qtype(); // The following adds the questiontype to the menu of types shown to teachers -$QTYPE_MENU[SHORTANSWER] = get_string("shortanswer", "quiz"); +$QTYPE_MENU['shortanswer'] = get_string("shortanswer", "quiz"); ?> diff --git a/question/questiontypes/truefalse/questiontype.php b/question/questiontypes/truefalse/questiontype.php index 32edb27d54..4b97325f53 100644 --- a/question/questiontypes/truefalse/questiontype.php +++ b/question/questiontypes/truefalse/questiontype.php @@ -312,9 +312,8 @@ class question_truefalse_qtype extends default_questiontype { ////////////////////////////////////////////////////////////////////////// //// INITIATION - Without this line the question type is not in use... /// ////////////////////////////////////////////////////////////////////////// -// define("TRUEFALSE", "2"); // already defined in questionlib.php -$QTYPES[TRUEFALSE]= new question_truefalse_qtype(); +$QTYPES['truefalse']= new question_truefalse_qtype(); // The following adds the questiontype to the menu of types shown to teachers -$QTYPE_MENU[TRUEFALSE] = get_string("truefalse", "quiz"); +$QTYPE_MENU['truefalse'] = get_string("truefalse", "quiz"); ?> -- 2.39.5