From 8f0f605ddfd0e892896985ab4c3d17f32d73e682 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Tue, 18 Sep 2007 11:23:29 +0000 Subject: [PATCH] moved question_make_default_categories function to questionlib.php since it is needed by other modules outside the question bank editing interface. --- lib/questionlib.php | 38 ++++++++++++++++++++++++++++++++++++++ question/editlib.php | 36 ------------------------------------ 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/lib/questionlib.php b/lib/questionlib.php index dab9ffb43b8..491554ac538 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -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. diff --git a/question/editlib.php b/question/editlib.php index 945a8a6f58e..6f201f8b1a9 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -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;