]> git.mjollnir.org Git - moodle.git/commitdiff
moved question_make_default_categories function to questionlib.php since it is needed...
authorjamiesensei <jamiesensei>
Tue, 18 Sep 2007 11:23:29 +0000 (11:23 +0000)
committerjamiesensei <jamiesensei>
Tue, 18 Sep 2007 11:23:29 +0000 (11:23 +0000)
lib/questionlib.php
question/editlib.php

index dab9ffb43b887a4f8c4b6e1ef1ead11225b64138..491554ac538c9173686e01caf71276b34f830b62 100644 (file)
@@ -1660,6 +1660,44 @@ function question_category_select_menu($contexts, $top = false, $currentcat = 0,
     choose_from_menu_nested($categoriesarray, 'category', $selected, $nothing);
 }
 
+/**
+* Gets the default category in the most specific context.
+* If no categories exist yet then default ones are created in all contexts.
+*
+* @param array $contexts  The context objects for this context and all parent contexts.
+* @return object The default category - the category in the course context
+*/
+function question_make_default_categories($contexts) {
+    $toreturn = null;
+    // If it already exists, just return it.
+    foreach ($contexts as $key => $context) {
+        if (!$categoryrs = get_recordset_select("question_categories", "contextid = '{$context->id}'", 'sortorder, name', '*', '', 1)) {
+            error('error getting category record');
+        } else {
+            if (!$category = rs_fetch_record($categoryrs)){
+                // Otherwise, we need to make one
+                $category = new stdClass;
+                $contextname = print_context_name($context, false, true);
+                $category->name = addslashes(get_string('defaultfor', 'question', $contextname));
+                $category->info = addslashes(get_string('defaultinfofor', 'question', $contextname));
+                $category->contextid = $context->id;
+                $category->parent = 0;
+                $category->sortorder = 999; // By default, all categories get this number, and are sorted alphabetically.
+                $category->stamp = make_unique_id_code();
+                if (!$category->id = insert_record('question_categories', $category)) {
+                    error('Error creating a default category for context '.print_context_name($context));
+                }
+            }
+        }
+        if ($context->contextlevel == CONTEXT_COURSE){
+            $toreturn = clone($category);
+        }
+    }
+
+
+    return $toreturn;
+}
+
 /**
  * Get all the category objects, including a count of the number of questions in that category,
  * for all the categories in the lists $contexts.
index 945a8a6f58e4848740d1b0e8376f9898d12c6ac4..6f201f8b1a958944d81bba258df75304b9bf1a07 100644 (file)
@@ -75,42 +75,6 @@ function get_questions_category( $category, $noparent=false, $recurse=true, $exp
     return $qresults;
 }
 
-/**
-* Gets the default category in the most specific context.
-* If no categories exist yet then default ones are created in all contexts.
-*
-* @param array $contexts  The context objects for this context and all parent contexts.
-* @return object The default category - the category in the course context
-*/
-function question_make_default_categories($contexts) {
-    // If it already exists, just return it.
-    foreach ($contexts as $key => $context) {
-        if (!$categoryrs = get_recordset_select("question_categories", "contextid = '{$context->id}'", 'sortorder, name', '*', '', 1)) {
-            error('error getting category record');
-        } else {
-            if (!$category = rs_fetch_record($categoryrs)){
-                // Otherwise, we need to make one
-                $category = new stdClass;
-                $contextname = print_context_name($context, false, true);
-                $category->name = addslashes(get_string('defaultfor', 'question', $contextname));
-                $category->info = addslashes(get_string('defaultinfofor', 'question', $contextname));
-                $category->contextid = $context->id;
-                $category->parent = 0;
-                $category->sortorder = 999; // By default, all categories get this number, and are sorted alphabetically.
-                $category->stamp = make_unique_id_code();
-                if (!$category->id = insert_record('question_categories', $category)) {
-                    error('Error creating a default category for context '.print_context_name($context));
-                }
-            }
-        }
-        if ($context->contextlevel == CONTEXT_COURSE){
-            $toreturn = clone($category);
-        }
-    }
-
-
-    return $toreturn;
-}
 
 function question_can_delete_cat($todelete){
     global $CFG;