]> git.mjollnir.org Git - moodle.git/commitdiff
Breadcrumbs: Core functionality changes
authormattc-catalyst <mattc-catalyst>
Mon, 16 Apr 2007 20:44:32 +0000 (20:44 +0000)
committermattc-catalyst <mattc-catalyst>
Mon, 16 Apr 2007 20:44:32 +0000 (20:44 +0000)
- 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 <mattc@catalyst.net.nz>
Committer: Matt Clarkson <mattc@catalyst.net.nz>

lib/moodlelib.php
lib/weblib.php

index 4cb346d8f07fa51657cbb7a04d86b5b70cc54d69..bcbf4f078c698f17eef2828d53058e19c6b8f46c 100644 (file)
@@ -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 = "<ul>\n";
+    $countcrumb = count($breadcrumbs);
+   
+    for($i=0;$i<$countcrumb;$i++) {
+   
+        // Check the link type to see if this link should appear in the trail
+        if ($breadcrumbs[$i]['type'] == 'activity' && $i+1 < $countcrumb && ($CFG->hideactivitytypecrumb == 2  || ($CFG->hideactivitytypecrumb == 1 && !has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))))) {
+            continue;
+        }
+        $navigation .= '<li class="first">';
+        if ($i > 0) {
+            $navigation .= '<span class="sep"> '.$THEME->rarrow.' </span>';
+        }
+        if ($breadcrumbs[$i]['link'] && $i+1 < $countcrumb) {
+            $navigation .= "<a onclick=\"this.target='$CFG->framename'\" href=\"{$breadcrumbs[$i]['link']}\">";
+        }
+        $navigation .= "{$breadcrumbs[$i]['name']}";
+        if ($breadcrumbs[$i]['link'] && $i+1 < $countcrumb) {
+            $navigation .= "</a>";
+        }
+               
+        $navigation .= "</li>";
+    }
+    
+    $navigation .= "</ul>";
+
+    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:
 ?>
index f9ee736571a3c15d69301110f007acc94f6f3efc..8a93b32b103e10768a4f83a31cb26b8b73cfa19b 100644 (file)
@@ -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 = '<a href="'.$CFG->wwwroot.'/course/view.php?id='. $COURSE->id .'">'. $COURSE->shortname .'</a> ->';
     }
 
-    $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);