From 35a5d3b2fc37b4557b098a450ff5df21790a8d11 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Wed, 13 Jul 2011 09:58:42 +0800 Subject: [PATCH] MDL-28040 navigation: Fixed up error with navigation when dealing with categories that have a lower sort order than the parent. --- lib/navigationlib.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 9159cc22b9a..723ab3a833c 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1283,7 +1283,7 @@ class global_navigation extends navigation_node { $coursestoload = array(); if (empty($categoryid)) { // can be 0 // We are going to load all of the first level categories (categories without parents) - $categories = $DB->get_records('course_categories', array('parent'=>'0'), 'sortorder'); + $categories = $DB->get_records('course_categories', array('parent'=>'0'), 'sortorder ASC, id ASC'); } else if (array_key_exists($categoryid, $this->addedcategories)) { // The category itself has been loaded already so we just need to ensure its subcategories // have been loaded @@ -1294,13 +1294,13 @@ class global_navigation extends navigation_node { FROM {course_categories} cc WHERE (parent = :categoryid OR parent = 0) AND parent {$sql} - ORDER BY sortorder"; + ORDER BY depth DESC, sortorder ASC, id ASC"; } else { $sql = "SELECT * FROM {course_categories} cc WHERE parent = :categoryid AND parent {$sql} - ORDER BY sortorder"; + ORDER BY depth DESC, sortorder ASC, id ASC"; } $params['categoryid'] = $categoryid; $categories = $DB->get_records_sql($sql, $params); @@ -1339,7 +1339,11 @@ class global_navigation extends navigation_node { if (!array_key_exists($catid, $this->addedcategories)) { // This category isn't in the navigation yet so add it. $subcategory = $categories[$catid]; - if (array_key_exists($subcategory->parent, $this->addedcategories)) { + if ($subcategory->parent == '0') { + // Yay we have a root category - this likely means we will now be able + // to add categories without problems. + $this->add_category($subcategory, $this->rootnodes['courses']); + } else if (array_key_exists($subcategory->parent, $this->addedcategories)) { // The parent is in the category (as we'd expect) so add it now. $this->add_category($subcategory, $this->addedcategories[$subcategory->parent]); // Remove the category from the categories array.