MDL-39127 navigation: fixed loading of categories for navbar

This commit is contained in:
Sam Hemelryk 2013-04-16 11:02:06 +12:00
parent 9aae7551ec
commit 2fb77a96b3

View File

@ -3061,14 +3061,26 @@ class navbar extends navigation_node {
*/ */
private function get_course_categories() { private function get_course_categories() {
$categories = array(); $categories = array();
$id = $this->page->course->category; foreach ($this->page->categories as $category) {
while ($id) { $url = new moodle_url('/course/index.php', array('categoryid' => $category->id));
$category = coursecat::get($id); $name = format_string($category->name, true, array('context' => context_coursecat::instance($category->id)));
$url = new moodle_url('/course/index.php', array('categoryid' => $id)); $categories[] = navigation_node::create($name, $url, self::TYPE_CATEGORY, null, $category->id);
$categories[] = navigation_node::create($category->get_formatted_name(), $url, self::TYPE_CATEGORY, null, $id);
$id = $category->parent; $id = $category->parent;
} }
$categories[] = $this->page->navigation->get('courses'); if (is_enrolled(context_course::instance($this->page->course->id))) {
$courses = $this->page->navigation->get('mycourses');
} else {
$courses = $this->page->navigation->get('courses');
}
if (!$courses) {
// Courses node may not be present.
$courses = navigation_node::create(
get_string('courses'),
new moodle_url('/course/index.php'),
self::TYPE_CONTAINER
);
}
$categories[] = $courses;
return $categories; return $categories;
} }