Permalink
Browse files

MDL-27940 navigaiton: Fixed an ordering problem so that when a parent…

… was set for a node the nodes activity was accounted for
  • Loading branch information...
1 parent 3552484 commit d38a4849b79952aca80d22f7d80bae0ca8939ef4 Sam Hemelryk committed Jun 23, 2011
Showing with 23 additions and 5 deletions.
  1. +23 −5 lib/navigationlib.php
View
@@ -117,7 +117,7 @@ class navigation_node implements renderable {
public $mainnavonly = false;
/** @var bool If set to true a title will be added to the action no matter what */
public $forcetitle = false;
- /** @var navigation_node A reference to the node parent */
+ /** @var navigation_node A reference to the node parent, you should never set this directly you should always call set_parent */
public $parent = null;
/** @var bool Override to not display the icon even if one is provided **/
public $hideicon = false;
@@ -169,9 +169,6 @@ public function __construct($properties) {
if (array_key_exists('key', $properties)) {
$this->key = $properties['key'];
}
- if (array_key_exists('parent', $properties)) {
- $this->parent = $properties['parent'];
- }
// This needs to happen last because of the check_if_active call that occurs
if (array_key_exists('action', $properties)) {
$this->action = $properties['action'];
@@ -182,6 +179,9 @@ public function __construct($properties) {
$this->check_if_active();
}
}
+ if (array_key_exists('parent', $properties)) {
+ $this->set_parent($properties['parent']);
+ }
} else if (is_string($properties)) {
$this->text = $properties;
}
@@ -305,7 +305,7 @@ public function add_node(navigation_node $childnode, $beforekey=null) {
$this->nodetype = self::NODETYPE_BRANCH;
}
// Set the parent to this node
- $childnode->parent = $this;
+ $childnode->set_parent($this);
// Default the key to the number of children if not provided
if ($childnode->key === null) {
@@ -648,6 +648,24 @@ public function get_tabs_array(array $inactive=array(), $return=false) {
}
return array(array($tabs, $rows), $selected, $inactive, $activated, $return);
}
+
+ /**
+ * Sets the parent for this node and if this node is active ensures that the tree is properly
+ * adjusted as well.
+ *
+ * @param navigation_node $parent
+ */
+ public function set_parent(navigation_node $parent) {
+ // Set the parent (thats the easy part)
+ $this->parent = $parent;
+ // Check if this node is active (this is checked during construction)
+ if ($this->isactive) {
+ // Force all of the parent nodes open so you can see this node
+ $this->parent->force_open();
+ // Make all parents inactive so that its clear where we are.
+ $this->parent->make_inactive();
+ }
+ }
}
/**

0 comments on commit d38a484

Please sign in to comment.