Skip to content

Commit

Permalink
MDL-38442 navigation: set_expansion_limit now only hides structural n…
Browse files Browse the repository at this point in the history
…odes
  • Loading branch information
Sam Hemelryk committed Apr 9, 2013
1 parent 7d253e0 commit 0f16db9
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions lib/navigationlib.php
Expand Up @@ -667,12 +667,18 @@ public function set_parent(navigation_node $parent) {
* Hides the node and any children it has. * Hides the node and any children it has.
* *
* @since 2.3.5 * @since 2.3.5
* @param array $typestohide Optional. An array of node types that should be hidden.
* If null all nodes will be hidden.
* If an array is given then nodes will only be hidden if their type mtatches an element in the array.
* e.g. array(navigation_node::TYPE_COURSE) would hide only course nodes.
*/ */
public function hide() { public function hide(array $typestohide = null) {
$this->display = false; if ($typestohide === null || in_array($this->type, $typestohide)) {
if ($this->has_children()) { $this->display = false;
foreach ($this->children as $child) { if ($this->has_children()) {
$child->hide(); foreach ($this->children as $child) {
$child->hide($typestohide);
}
} }
} }
} }
Expand Down Expand Up @@ -2745,18 +2751,24 @@ public function clear_cache() {
public function set_expansion_limit($type) { public function set_expansion_limit($type) {
global $SITE; global $SITE;
$nodes = $this->find_all_of_type($type); $nodes = $this->find_all_of_type($type);

// We only want to hide specific types of nodes.
// Only nodes that represent "structure" in the navigation tree should be hidden.
// If we hide all nodes then we risk hiding vital information.
$typestohide = array(
self::TYPE_CATEGORY,
self::TYPE_COURSE,
self::TYPE_SECTION,
self::TYPE_ACTIVITY
);

foreach ($nodes as $node) { foreach ($nodes as $node) {
// We need to generate the full site node // We need to generate the full site node
if ($type == self::TYPE_COURSE && $node->key == $SITE->id) { if ($type == self::TYPE_COURSE && $node->key == $SITE->id) {
continue; continue;
} }
foreach ($node->children as $child) { foreach ($node->children as $child) {
// We still want to show course reports and participants containers $child->hide($typestohide);
// or there will be navigation missing.
if ($type == self::TYPE_COURSE && $child->type === self::TYPE_CONTAINER) {
continue;
}
$child->hide();
} }
} }
return true; return true;
Expand Down

0 comments on commit 0f16db9

Please sign in to comment.