Browse files

MDL-37762 navbar: shows categories for current course again

  • Loading branch information...
1 parent 7a5f376 commit ce520e04707561224a9ca5c6fb15a8ad89d2eb5b Sam Hemelryk committed Apr 14, 2013
Showing with 9 additions and 17 deletions.
  1. +9 −17 lib/navigationlib.php
View
26 lib/navigationlib.php
@@ -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,11 +3053,8 @@ public function get_items() {
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;
}
@@ -3066,11 +3064,8 @@ public function get_items() {
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;
}
@@ -3109,13 +3104,10 @@ 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))
- ));
+ $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');

0 comments on commit ce520e0

Please sign in to comment.