]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13189 - replace the $QTYPE_MENU global with a function call, so that we can set...
authortjhunt <tjhunt>
Thu, 28 Feb 2008 12:53:02 +0000 (12:53 +0000)
committertjhunt <tjhunt>
Thu, 28 Feb 2008 12:53:02 +0000 (12:53 +0000)
lib/questionlib.php
question/editlib.php
question/type/multianswer/edit_multianswer_form.php

index e702365046e60fee46d6950af3e682710cc8f9b8..543b7595ac1069235924ad74a5852e232f961807 100644 (file)
@@ -102,19 +102,11 @@ define('QUESTION_FILEMOVELINKSONLY', 4);
 /// QTYPES INITIATION //////////////////
 // These variables get initialised via calls to question_register_questiontype
 // as the question type classes are included.
-global $QTYPES, $QTYPE_MENU, $QTYPE_MANUAL, $QTYPE_EXCLUDE_FROM_RANDOM;
+global $QTYPES, $QTYPE_MANUAL, $QTYPE_EXCLUDE_FROM_RANDOM;
 /**
  * Array holding question type objects
  */
 $QTYPES = array();
-/**
- * Array of question types names translated to the user's language
- *
- * The $QTYPE_MENU array holds the names of all the question types that the user should
- * be able to create directly. Some internal question types like random questions are excluded.
- * The complete list of question types can be found in {@link $QTYPES}.
- */
-$QTYPE_MENU = array();
 /**
  * String in the format "'type1','type2'" that can be used in SQL clauses like
  * "WHERE q.type IN ($QTYPE_MANUAL)".
@@ -132,14 +124,10 @@ $QTYPE_EXCLUDE_FROM_RANDOM = '';
  * @param object $qtype An instance of the new question type class.
  */
 function question_register_questiontype($qtype) {
-    global $QTYPES, $QTYPE_MENU, $QTYPE_MANUAL, $QTYPE_EXCLUDE_FROM_RANDOM;
+    global $QTYPES, $QTYPE_MANUAL, $QTYPE_EXCLUDE_FROM_RANDOM;
 
     $name = $qtype->name();
     $QTYPES[$name] = $qtype;
-    $menuname = $qtype->menu_name();
-    if ($menuname) {
-        $QTYPE_MENU[$name] = $menuname;
-    }
     if ($qtype->is_manual_graded()) {
         if ($QTYPE_MANUAL) {
             $QTYPE_MANUAL .= ',';
@@ -170,6 +158,31 @@ foreach($qtypenames as $qtypename) {
     }
 }
 
+/**
+ * An array of question type names translated to the user's language, suitable for use when
+ * creating a drop-down menu of options.
+ *
+ * Long-time Moodle programmers will realise that this replaces the old $QTYPE_MENU array.
+ * The array returned will only hold the names of all the question types that the user should
+ * be able to create directly. Some internal question types like random questions are excluded.
+ * 
+ * @return array an array of question type names translated to the user's language.
+ */
+function question_type_menu() {
+    global $QTYPES;
+    static $menu_options = null;
+    if (is_null($menu_options)) {
+        $menu_options = array();
+        foreach ($QTYPES as $name => $qtype) {
+            $menuname = $qtype->menu_name();
+            if ($menuname) {
+                $menu_options[$name] = $menuname;
+            }
+        }
+    }
+    return $menu_options;
+}
+
 /// OTHER CLASSES /////////////////////////////////////////////////////////
 
 /**
index 2f5c45c153998dfce9c957220ee34ec944d57844..7e1b22077d739e68dfe0e46b240d86606bed74ba 100644 (file)
@@ -146,12 +146,11 @@ function question_category_form_checkbox($name, $checked) {
 function question_list($contexts, $pageurl, $categoryandcontext, $cm = null,
         $recurse=1, $page=0, $perpage=100, $showhidden=false, $sortorder='typename', $sortorderdecoded='qtype, name ASC',
         $showquestiontext = false, $addcontexts = array()) {
-    global $QTYPE_MENU, $USER, $CFG, $THEME, $COURSE;
+    global $USER, $CFG, $THEME, $COURSE;
 
     list($categoryid, $contextid)=  explode(',', $categoryandcontext);
 
-    $qtypemenu = $QTYPE_MENU;
-
+    $qtypemenu = question_type_menu();
 
     $strcategory = get_string("category", "quiz");
     $strquestion = get_string("question", "quiz");
index 804f51270710dc44a851d1c5d009902d40ca2e0b..055cfd9f7ff67316cbcddc27d87100a067f29ee9 100644 (file)
@@ -18,7 +18,7 @@ class question_edit_multianswer_form extends question_edit_form {
     var $questiondisplay ; 
 
     function definition_inner(&$mform) {
-        global $QTYPE_MENU;
+        $question_type_names = question_type_menu();
         $mform->addRule('questiontext', null, 'required', null, 'client');
 
         // Remove meaningless defaultgrade field.
@@ -50,7 +50,7 @@ class question_edit_multianswer_form extends question_edit_form {
                 $this->editas[$sub] = optional_param('sub_'.$sub."_".'qtype', '', PARAM_RAW);
             }
             $mform->addElement('header', 'subhdr', get_string('questionno', 'quiz',
-                 '{#'.$sub.'}').'&nbsp;'.$QTYPE_MENU[$this->questiondisplay->options->questions[$sub]->qtype]);
+                 '{#'.$sub.'}').'&nbsp;'.$question_type_names[$this->questiondisplay->options->questions[$sub]->qtype]);
 
             $mform->addElement('static', 'sub_'.$sub."_".'questiontext', "subquestiontext",array('cols'=>60, 'rows'=>3));