Skip to content

Commit

Permalink
Merge branch 'wip-MDL-28040-master' of git://github.com/samhemelryk/m…
Browse files Browse the repository at this point in the history
…oodle
  • Loading branch information
skodak committed Jul 18, 2011
2 parents fa9264b + c4afcf8 commit 696ddfe
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ protected function load_all_categories($categoryid = null, $showbasecategories =
$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
Expand All @@ -1417,13 +1417,13 @@ protected function load_all_categories($categoryid = null, $showbasecategories =
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);
Expand Down Expand Up @@ -1462,7 +1462,11 @@ protected function load_all_categories($categoryid = null, $showbasecategories =
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.
Expand Down

0 comments on commit 696ddfe

Please sign in to comment.