]> git.mjollnir.org Git - moodle.git/commitdiff
Cleanup: don't use questiontype constants within questiontypes
authorgustav_delius <gustav_delius>
Wed, 22 Mar 2006 13:51:25 +0000 (13:51 +0000)
committergustav_delius <gustav_delius>
Wed, 22 Mar 2006 13:51:25 +0000 (13:51 +0000)
15 files changed:
question/questiontypes/calculated/editquestion.php
question/questiontypes/calculated/questiontype.php
question/questiontypes/description/questiontype.php
question/questiontypes/essay/questiontype.php
question/questiontypes/match/questiontype.php
question/questiontypes/multianswer/editquestion.php
question/questiontypes/multianswer/questiontype.php
question/questiontypes/multichoice/questiontype.php
question/questiontypes/numerical/questiontype.php
question/questiontypes/questiontype.php
question/questiontypes/random/questiontype.php
question/questiontypes/randomsamatch/editquestion.php
question/questiontypes/randomsamatch/questiontype.php
question/questiontypes/shortanswer/questiontype.php
question/questiontypes/truefalse/questiontype.php

index 7e87a8b58e49353e2adeffd1b8c876fe9ac08b58..0c4e3c786653be2cae8524825ca9c94d01711355 100644 (file)
@@ -1,7 +1,7 @@
 <?php // $Id$
 
 // Get a handle to the question type we are dealing with here
-$qtypeobj = $QTYPES[CALCULATED];
+$qtypeobj = $QTYPES['calculated'];
 
 if (empty($form)) {
 /****************************************************************/
index 884d7bc7427bfd9267e151724a10a65f5e238359..c1623f1289c5869b4b8ccf78874f2e1d112bef01 100644 (file)
@@ -704,10 +704,9 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype
 //////////////////////////////////////////////////////////////////////////
 //// INITIATION - Without this line the question type is not in use... ///
 //////////////////////////////////////////////////////////////////////////
-// define("CALCULATED",   "10"); // already defined in questionlib.php
-$QTYPES[CALCULATED]= new question_calculated_qtype();
+$QTYPES['calculated']= new question_calculated_qtype();
 // The following adds the questiontype to the menu of types shown to teachers
-$QTYPE_MENU[CALCULATED] = get_string("calculated", "quiz");
+$QTYPE_MENU['calculated'] = get_string("calculated", "quiz");
 
 function quiz_qtype_calculated_calculate_answer($formula, $individualdata,
         $tolerance, $tolerancetype, $answerlength, $answerformat='1', $unit='') {
@@ -718,7 +717,7 @@ function quiz_qtype_calculated_calculate_answer($formula, $individualdata,
 
     /// Exchange formula variables with the correct values...
     global $QTYPES;
-    $answer = $QTYPES[CALCULATED]->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 ***/
 
index c8a4141195ec9ed17190dec7f1f0b3dd21647fe5..d8921d54d728d68cf4e6b48d4746418dc8039bb9 100644 (file)
@@ -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");
 
 ?>
index dc0d6d3f2ab4086fb9ba347d4a08f6c296b95aaa..19fe7b4e8aed013264125e4065b186bfd17ed3c1 100644 (file)
@@ -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");
 
 ?>
index 5035ba92ddaaf8687e1339261f386d79b316c463..32a3ad45c578e12781d7940c7f3213cbb31ffcf4 100644 (file)
@@ -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");
 
 ?>
index 8856cc5b89f0b7b5eee58f2fd5781c93a7e517e3..42dbdf20724c6e28bf480fddf6a65241caab4719 100644 (file)
@@ -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:
index c37ea7de2879fa2e67140ee17047c8fb0ab8af9e..f34308130e20cdba3ca18e3b8483eed831af69e9 100644 (file)
@@ -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 " <input $style $readonly $popup name=\"$inputname\"
                             type=\"text\" value=\"$response\" size=\"12\" /> ";
                     break;
-                case MULTICHOICE:
+                case 'multichoice':
                     $outputoptions = '<option></option>'; // 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.'<br />';
@@ -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]");
index b63a97b484336983ebdba8afbca9dd3e0bc7b68a..130c0f936e18a71a673a7b6370d8581e467f6411 100644 (file)
@@ -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");
 
 ?>
index 6231c205c297ef2597e913707c2887d567ed51eb..74c34d9dd14cd9421a906cf5034bc1f62478ff48 100644 (file)
@@ -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");
 
 ?>
index 4822cb1743f372f7b1babbdfbf86d9055546deef..3ea06b474f60aa8b2ad1f04a958ab1b1d67050b2 100644 (file)
@@ -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
index 77e8e7547e23f444849cf24d00c03f23df42bb7f..71c48dc6f18fb4bdd269a5c888669d84fbaff94b 100644 (file)
@@ -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 = '<span class="notifyproblem">'.
          get_string('toomanyrandom', 'quiz'). '</span>';
-        $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 = '<span class="notifyproblem">'.
                  get_string('toomanyrandom', 'quiz'). '</span>';
-                $question->qtype = DESCRIPTION;
+                $question->qtype = 'description';
                 return true;
             }
             // this must be an old-style state which stores only the id for the wrapped question
index 4a039dce92bee8817d10b582db0649e03f385a7f..ee53a95d78a9b58ff1675087581ef4de0fd60713 100644 (file)
@@ -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);
 
index 25ee59fc40a147a6852e8953bef2cea624584100..d3d214a6a03d9dedc46642b22748e9758951c69f 100644 (file)
@@ -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");
 
 ?>
index c6c8c866810acf2d334f90d5e957ed0a48398c86..27543aa6591254f0fb4df232c3fe0d8ae23ccdd3 100644 (file)
@@ -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");
 
 ?>
index 32edb27d54e1c9f9bcfeb2dfd909f8f9864d2fd1..4b97325f53e245351bd497c2c4c3b0fa3d3b1b68 100644 (file)
@@ -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");
 
 ?>