From: tjhunt Date: Mon, 5 Mar 2007 18:05:51 +0000 (+0000) Subject: MDL-8764 - In menus, show question categories from this course first, then published... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b030a630c0eb83556db755b09eb160c7c9ff0939;p=moodle.git MDL-8764 - In menus, show question categories from this course first, then published categories from other courses. Merged from MOODLE_18_STABLE. --- diff --git a/lib/questionlib.php b/lib/questionlib.php index 20e217541c..ccbc2c74ee 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1578,7 +1578,7 @@ function question_category_options($courseid, $published = false, $only_editable SELECT cat.*, c.shortname AS coursename FROM {$CFG->prefix}question_categories cat, {$CFG->prefix}course c WHERE c.id = cat.course AND (cat.course = $courseid $publishsql) - ORDER BY cat.parent, cat.sortorder, cat.name ASC"); + ORDER BY (CASE WHEN cat.course = $courseid THEN 0 ELSE 1 END), cat.parent, cat.sortorder, cat.name ASC"); $categories = add_indented_names($categories); $categoriesarray = array(); diff --git a/question/editlib.php b/question/editlib.php index 9ad4be49a2..cf429b9abd 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -69,20 +69,18 @@ function get_questions_category( $category, $noparent=false, $recurse=true ) { * @param integer $courseid The id of the course whose default category is wanted */ function get_default_question_category($courseid) { - - if ($categories = get_records_select("question_categories", "course = '$courseid' AND parent = '0'", "id")) { - foreach ($categories as $category) { - return $category; // Return the first one (lowest id) - } + // If it already exists, just return it. + if ($category = get_records_select("question_categories", "course = '$courseid' AND parent = '0'", 'id', '*', '', 1)) { + return reset($category); } // Otherwise, we need to make one + $category = new stdClass; $category->name = get_string("default", "quiz"); $category->info = get_string("defaultinfo", "quiz"); $category->course = $courseid; $category->parent = 0; - // TODO: Figure out why we use 999 below - $category->sortorder = 999; + $category->sortorder = 999; // By default, all categories get this number, and are sorted alphabetically. $category->publish = 0; $category->stamp = make_unique_id_code(); @@ -100,27 +98,11 @@ function question_category_form($course, $current, $recurse=1, $showhidden=false global $CFG; /// Make sure the default category exists for this course - if (!$categories = get_records("question_categories", "course", $course->id, "id ASC")) { - if (!$category = get_default_question_category($course->id)) { - notify("Error creating a default category!"); - } - } + get_default_question_category($course->id); /// Get all the existing categories now - if (!$categories = get_records_select("question_categories", "course = '{$course->id}' OR publish = '1'", "parent, sortorder, name ASC")) { - notify("Could not find any question categories!"); - return false; // Something is really wrong - } + $catmenu = question_category_options($course->id, true); - $categories = add_indented_names( $categories ); - foreach ($categories as $key => $category) { - if ($catcourse = get_record("course", "id", $category->course)) { - if ($category->publish && $category->course != $course->id) { - $category->indentedname .= " ($catcourse->shortname)"; - } - $catmenu[$category->id] = $category->indentedname; - } - } $strcategory = get_string("category", "quiz"); $strshow = get_string("show", "quiz"); $streditcats = get_string("editcategories", "quiz"); diff --git a/question/export.php b/question/export.php index d821827cac..4437e6cef6 100644 --- a/question/export.php +++ b/question/export.php @@ -50,9 +50,7 @@ } } - if (! $category = get_record("question_categories", "id", $categoryid)) { - $category = get_default_question_category($courseid); - } + $category = get_default_question_category($courseid); if (! $categorycourse = get_record("course", "id", $category->course)) { error( $txt->nocategory ); diff --git a/question/import.php b/question/import.php index 987bdb99de..034c3bbce5 100644 --- a/question/import.php +++ b/question/import.php @@ -194,31 +194,7 @@ print_heading_with_help($txt->importquestions, "import", "quiz"); /// Get all the existing categories now - if (has_capability('moodle/question:manage', get_context_instance(CONTEXT_SYSTEM, SITEID))) { // the admin can import into all categories - if (!$categories = get_records_select("question_categories", "course = '{$course->id}' OR publish = '1'", "parent, sortorder, name ASC")) { - error("Could not find any question categories!"); // Something is really wrong - } - } else { // select only the categories to which the teacher has write access - $cats = get_records('question_categories'); - $categories = array(); - foreach ($cats as $cat) { - if (has_capability('moodle/question:managecategory', get_context_instance(CONTEXT_COURSE, $cat->course))) { - $categories[] = $cat; - } - } - if (empty($categories)) { - error("Could not find any question categories!"); - } - } - $categories = add_indented_names($categories); - foreach ($categories as $key => $cat) { - if ($catcourse = get_record("course", "id", $cat->course)) { - if ($cat->publish && $cat->course != $course->id) { - $cat->indentedname .= " ($catcourse->shortname)"; - } - $catmenu[$cat->id] = $cat->indentedname; - } - } + $catmenu = question_category_options($course->id, false, true); //========== // DISPLAY