From ac4feb59affaf91f3b51c173b30a549bfa31cc84 Mon Sep 17 00:00:00 2001 From: mattc-catalyst Date: Mon, 16 Apr 2007 20:44:32 +0000 Subject: [PATCH] Breadcrumbs: Core functionality changes - Added build_navigation function to create an XHTML breadcrumb list and to allow filtering of breadcrumbs to remove the activity from the trail. - modified print_navigation to print the output of build_navigation whilst maintaining backward compatibility with old style string breadcrumbs. Author: Matt Clarkson Committer: Matt Clarkson --- lib/moodlelib.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++ lib/weblib.php | 31 ++++++++++++++++---- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 4cb346d8f0..bcbf4f078c 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -6925,5 +6925,78 @@ function setup_lang_from_browser() { return; } + +//////////////////////////////////////////////////////////////////////////////// +/** + * This function will build the navigation string to be used by print_header + * and others + * @uses $CFG + * @uses $THEME + * @param $extrabreadcrumbs - array of associative arrays, keys: name, link, type + * @param $course - possibily the site course. + * @return $navigation as an object so it can be differentiated from old style + * navigation strings. + */ +function build_navigation($extrabreadcrumbs, $course = false) { + global $CFG, $THEME; + + $navigation = ''; + check_theme_arrows(); + + //Site name + if ($site = get_site()) { + $breadcrumbs[] = array('name' => format_string($site->shortname), 'link' => "$CFG->wwwroot/", 'type' => 'home'); + } + + + if ($course) { + if ($course->id != SITEID) { + //Course + $breadcrumbs[] = array('name' => format_string($course->shortname), 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",'type' => 'course'); + } + } + + //Merge in extra bread crumbs + $breadcrumbs = array_merge($breadcrumbs, $extrabreadcrumbs); + + //Construct an unordered list from $breadcrumbs + $navigation = ""; + + return(array('newnav' => true, 'breadcrumbs' => $navigation)); + +} + +function is_newnav($navigation) { + if (is_array($navigation) && $navigation['newnav']) { + return(true); + } else { + return(false); + } +} + // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: ?> diff --git a/lib/weblib.php b/lib/weblib.php index f9ee736571..8a93b32b10 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2127,12 +2127,15 @@ function print_header ($title='', $heading='', $navigation='', $focus='', /// Add the required JavaScript Libraries $meta .= "\n".require_js(); - - if ($navigation == 'home') { - $home = true; - $navigation = ''; - } else { + if(is_newnav($navigation)){ $home = false; + } else { + if ($navigation == 'home') { + $home = true; + $navigation = ''; + } else { + $home = false; + } } /// This is another ugly hack to make navigation elements available to print_footer later @@ -2362,7 +2365,12 @@ function print_header_simple($title='', $heading='', $navigation='', $focus='', $shortname = ''. $COURSE->shortname .' ->'; } - $output = print_header($COURSE->shortname .': '. $title, $COURSE->fullname .' '. $heading, $shortname.' '. $navigation, $focus, $meta, + // If old style nav prepend course short name otherwise leave $navigation object alone + if (!is_newnav($navigation)) { + $navigation = $shortname.' '.$navigation; + } + + $output = print_header($COURSE->shortname .': '. $title, $COURSE->fullname .' '. $heading, $navigation, $focus, $meta, $cache, $button, $menu, $usexml, $bodytags, true); if ($return) { @@ -2855,6 +2863,17 @@ function print_navigation ($navigation, $separator=0, $return=false) { } if ($navigation) { + + if (is_newnav($navigation)) { + if ($return) { + return($navigation['breadcrumbs']); + } else { + echo $navigation['breadcrumbs']; + return; + } + } else { + debugging('Navigation needs to be updated to use build_navigation()', DEBUG_DEVELOPER); + } if (!is_array($navigation)) { $ar = explode('->', $navigation); -- 2.39.5