From 75bdae9f6e8b4da517d0be785ce8623140a7e7a1 Mon Sep 17 00:00:00 2001 From: Paul Nicholls Date: Fri, 12 Apr 2013 16:40:12 +1200 Subject: [PATCH 1/2] MDL-37762: Breadcrumb not showing categories on course page --- lib/navigationlib.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index eab4bd30317..2e2ec749a21 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -3007,6 +3007,12 @@ class navbar extends navigation_node { if (!$navigationactivenode->mainnavonly) { $items[] = $navigationactivenode; } + if ($navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') { + $categories = $this->get_course_categories(); + foreach ($categories as $category) { + $items[] = $category; + } + } $navigationactivenode = $navigationactivenode->parent; } } else if ($navigationactivenode) { @@ -3015,6 +3021,12 @@ class navbar extends navigation_node { if (!$navigationactivenode->mainnavonly) { $items[] = $navigationactivenode; } + if ($navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') { + $categories = $this->get_course_categories(); + foreach ($categories as $category) { + $items[] = $category; + } + } $navigationactivenode = $navigationactivenode->parent; } } else if ($settingsactivenode) { @@ -3039,6 +3051,32 @@ class navbar extends navigation_node { return $this->items; } + /** + * Get the list of categories leading to this course. + * + * This function is used by {@link navbar::get_items()} to add back the "courses" + * node and category chain leading to the current course. Note that this is only ever + * called for the current course, so we don't need to bother taking in any parameters. + * + * @return array + */ + private function get_course_categories() { + $categories = array(); + $id = $this->page->course->category; + while ($id) { + $category = coursecat::get($id); + $categories[] = new navigation_node(array( + 'text'=>$category->name, + 'shorttext'=>$category->name, + 'key'=>$category->idnumber, + 'action'=>new moodle_url('/course/category.php', array('id'=>$id)) + )); + $id = $category->parent; + } + $categories[] = $this->page->navigation->get('courses'); + return $categories; + } + /** * Add a new navigation_node to the navbar, overrides parent::add * From abb29010f317896b4b278912bc8caa1ceaa8088e Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Mon, 15 Apr 2013 11:25:53 +1200 Subject: [PATCH 2/2] MDL-37762 navbar: shows categories for current course again --- lib/navigationlib.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 2e2ec749a21..bd2addc6500 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -2971,6 +2971,7 @@ class navbar extends navigation_node { * @return array */ public function get_items() { + global $CFG; $items = array(); // Make sure that navigation is initialised if (!$this->has_items()) { @@ -3007,11 +3008,8 @@ class navbar extends navigation_node { if (!$navigationactivenode->mainnavonly) { $items[] = $navigationactivenode; } - if ($navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') { - $categories = $this->get_course_categories(); - foreach ($categories as $category) { - $items[] = $category; - } + if (!empty($CFG->navshowcategories) && $navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') { + $items = array_merge($items, $this->get_course_categories()); } $navigationactivenode = $navigationactivenode->parent; } @@ -3021,11 +3019,8 @@ class navbar extends navigation_node { if (!$navigationactivenode->mainnavonly) { $items[] = $navigationactivenode; } - if ($navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') { - $categories = $this->get_course_categories(); - foreach ($categories as $category) { - $items[] = $category; - } + if (!empty($CFG->navshowcategories) && $navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') { + $items = array_merge($items, $this->get_course_categories()); } $navigationactivenode = $navigationactivenode->parent; } @@ -3065,12 +3060,8 @@ class navbar extends navigation_node { $id = $this->page->course->category; while ($id) { $category = coursecat::get($id); - $categories[] = new navigation_node(array( - 'text'=>$category->name, - 'shorttext'=>$category->name, - 'key'=>$category->idnumber, - 'action'=>new moodle_url('/course/category.php', array('id'=>$id)) - )); + $url = new moodle_url('/course/category.php', array('id' => $id)); + $categories[] = navigation_node::create($category->get_formatted_name(), $url, self::TYPE_CATEGORY, null, $id); $id = $category->parent; } $categories[] = $this->page->navigation->get('courses');