MDL-8764 - In menus, show question categories from this course first, then published categories from other courses. Merged from MOODLE_18_STABLE.

This commit is contained in:
tjhunt 2007-03-05 18:05:51 +00:00
parent 6db0338e0e
commit b030a630c0
4 changed files with 10 additions and 54 deletions

View File

@ -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();

View File

@ -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");

View File

@ -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 );

View File

@ -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