/** * 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() { global $CFG; require_once $CFG->dirroot . '/course/lib.php'; require_once $CFG->libdir . '/coursecatlib.php'; $categories = array(); $cap = 'moodle/category:viewhiddencategories'; $showcategories = coursecat::count_all() > 1; if ($showcategories) { foreach ($this->page->categories as $category) { if (!$category->visible && !has_capability($cap, get_category_or_system_context($category->parent))) { continue; } $url = new moodle_url('/course/index.php', array('categoryid' => $category->id)); $name = format_string($category->name, true, array('context' => context_coursecat::instance($category->id))); $categorynode = breadcrumb_navigation_node::create($name, $url, self::TYPE_CATEGORY, null, $category->id); if (!$category->visible) { $categorynode->hidden = true; } $categories[] = $categorynode; } } // Don't show the 'course' node if enrolled in this course. if (!is_enrolled(context_course::instance($this->page->course->id, null, '', true))) { $courses = $this->page->navigation->get('courses'); if (!$courses) { // Courses node may not be present. $courses = breadcrumb_navigation_node::create(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_CONTAINER); } $categories[] = $courses; } return $categories; }
/** * Renders a breadcrumb navigation node object. * * @param breadcrumb_navigation_node $item The navigation node to render. * @return string HTML fragment */ protected function render_breadcrumb_navigation_node(breadcrumb_navigation_node $item) { if ($item->action instanceof moodle_url) { $content = $item->get_content(); $title = $item->get_title(); $attributes = array(); $attributes['itemprop'] = 'url'; if ($title !== '') { $attributes['title'] = $title; } if ($item->hidden) { $attributes['class'] = 'dimmed_text'; } $content = html_writer::tag('span', $content, array('itemprop' => 'title')); $content = html_writer::link($item->action, $content, $attributes); $attributes = array(); $attributes['itemscope'] = ''; $attributes['itemtype'] = 'http://data-vocabulary.org/Breadcrumb'; $content = html_writer::tag('span', $content, $attributes); } else { $content = $this->render_navigation_node($item); } return $content; }