Permalink
Browse files

Merge branch 'wip-MDL-37762-m24' of https://github.com/samhemelryk/mo…

…odle into MOODLE_24_STABLE
  • Loading branch information...
damyon committed Apr 15, 2013
2 parents 6e0b5a7 + ce520e0 commit 6bf520165bc9aeb9c96aa9213a5d9c95dbfe2288
Showing with 30 additions and 0 deletions.
  1. +30 −0 lib/navigationlib.php
View
@@ -3016,6 +3016,7 @@ public function get($key, $type = null) {
* @return array
*/
public function get_items() {
+ global $CFG;
$items = array();
// Make sure that navigation is initialised
if (!$this->has_items()) {
@@ -3052,6 +3053,9 @@ public function get_items() {
if (!$navigationactivenode->mainnavonly) {
$items[] = $navigationactivenode;
}
+ if (!empty($CFG->navshowcategories) && $navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') {
+ $items = array_merge($items, $this->get_course_categories());
+ }
$navigationactivenode = $navigationactivenode->parent;
}
} else if ($navigationactivenode) {
@@ -3060,6 +3064,9 @@ public function get_items() {
if (!$navigationactivenode->mainnavonly) {
$items[] = $navigationactivenode;
}
+ if (!empty($CFG->navshowcategories) && $navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') {
+ $items = array_merge($items, $this->get_course_categories());
+ }
$navigationactivenode = $navigationactivenode->parent;
}
} else if ($settingsactivenode) {
@@ -3084,6 +3091,29 @@ public function get_items() {
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 = get_course_category($id);
+ $url = new moodle_url('/course/category.php', array('id' => $id));
+ $name = format_string($category->name, true, context_coursecat::instance($category->id));
+ $categories[] = navigation_node::create($name, $url, self::TYPE_CATEGORY, null, $id);
+ $id = $category->parent;
+ }
+ $categories[] = $this->page->navigation->get('courses');
+ return $categories;
+ }
+
/**
* Add a new navigation_node to the navbar, overrides parent::add
*

0 comments on commit 6bf5201

Please sign in to comment.