Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-37762 navbar: shows categories for current course again

  • Loading branch information...
commit ce520e04707561224a9ca5c6fb15a8ad89d2eb5b 1 parent 7a5f376
Sam Hemelryk samhemelryk authored

Showing 1 changed file with 9 additions and 17 deletions. Show diff stats Hide diff stats

  1. +9 17 lib/navigationlib.php
26 lib/navigationlib.php
@@ -3016,6 +3016,7 @@ public function get($key, $type = null) {
3016 3016 * @return array
3017 3017 */
3018 3018 public function get_items() {
  3019 + global $CFG;
3019 3020 $items = array();
3020 3021 // Make sure that navigation is initialised
3021 3022 if (!$this->has_items()) {
@@ -3052,11 +3053,8 @@ public function get_items() {
3052 3053 if (!$navigationactivenode->mainnavonly) {
3053 3054 $items[] = $navigationactivenode;
3054 3055 }
3055   - if ($navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') {
3056   - $categories = $this->get_course_categories();
3057   - foreach ($categories as $category) {
3058   - $items[] = $category;
3059   - }
  3056 + if (!empty($CFG->navshowcategories) && $navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') {
  3057 + $items = array_merge($items, $this->get_course_categories());
3060 3058 }
3061 3059 $navigationactivenode = $navigationactivenode->parent;
3062 3060 }
@@ -3066,11 +3064,8 @@ public function get_items() {
3066 3064 if (!$navigationactivenode->mainnavonly) {
3067 3065 $items[] = $navigationactivenode;
3068 3066 }
3069   - if ($navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') {
3070   - $categories = $this->get_course_categories();
3071   - foreach ($categories as $category) {
3072   - $items[] = $category;
3073   - }
  3067 + if (!empty($CFG->navshowcategories) && $navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') {
  3068 + $items = array_merge($items, $this->get_course_categories());
3074 3069 }
3075 3070 $navigationactivenode = $navigationactivenode->parent;
3076 3071 }
@@ -3109,13 +3104,10 @@ private function get_course_categories() {
3109 3104 $categories = array();
3110 3105 $id = $this->page->course->category;
3111 3106 while ($id) {
3112   - $category = coursecat::get($id);
3113   - $categories[] = new navigation_node(array(
3114   - 'text'=>$category->name,
3115   - 'shorttext'=>$category->name,
3116   - 'key'=>$category->idnumber,
3117   - 'action'=>new moodle_url('/course/category.php', array('id'=>$id))
3118   - ));
  3107 + $category = get_course_category($id);
  3108 + $url = new moodle_url('/course/category.php', array('id' => $id));
  3109 + $name = format_string($category->name, true, context_coursecat::instance($category->id));
  3110 + $categories[] = navigation_node::create($name, $url, self::TYPE_CATEGORY, null, $id);
3119 3111 $id = $category->parent;
3120 3112 }
3121 3113 $categories[] = $this->page->navigation->get('courses');

0 comments on commit ce520e0

Please sign in to comment.
Something went wrong with that request. Please try again.