navigation MDL-22044 Added setting to limit content that is shown on the navigation back into the navigation block

This commit is contained in:
Sam Hemelryk
2010-04-21 09:44:16 +00:00
parent 8f57314b1e
commit 88f77c3c26
7 changed files with 55 additions and 13 deletions
+23 -1
View File
@@ -512,7 +512,7 @@ class navigation_node implements renderable {
return;
}
foreach ($this->children as &$child) {
if ($child->nodetype == self::NODETYPE_BRANCH && $child->children->count()==0) {
if ($child->nodetype == self::NODETYPE_BRANCH && $child->children->count()==0 && $child->display) {
$child->id = 'expandable_branch_'.(count($expandable)+1);
$this->add_class('canexpand');
$expandable[] = array('id'=>$child->id,'branchid'=>$child->key,'type'=>$child->type);
@@ -520,6 +520,15 @@ class navigation_node implements renderable {
$child->find_expandable($expandable);
}
}
public function find_all_of_type($type) {
$nodes = $this->children->type($type);
foreach ($this->children as &$node) {
$childnodes = $node->find_all_of_type($type);
$nodes = array_merge($nodes, $childnodes);
}
return $nodes;
}
}
/**
@@ -744,6 +753,9 @@ class global_navigation extends navigation_node {
protected $cache;
/** @var array */
protected $addedcourses = array();
/** @var int */
protected $expansionlimit = 0;
/**
* Constructs a new global navigation
*
@@ -1481,6 +1493,16 @@ class global_navigation extends navigation_node {
public function clear_cache() {
$this->cache->clear();
}
public function set_expansion_limit($type) {
$nodes = $this->find_all_of_type($type);
foreach ($nodes as &$node) {
foreach ($node->children as &$child) {
$child->display = false;
}
}
return true;
}
}
/**