Ejemplo n.º 1
0
 /**
  * Adds a navigation node as a child of this one, given a $node object
  * created using the create function.
  * @param navigation_node $childnode Node to add
  * @param string $beforekey
  * @return navigation_node The added node
  */
 public function add_node(navigation_node $childnode, $beforekey = null)
 {
     // First convert the nodetype for this node to a branch as it will now have children
     if ($this->nodetype !== self::NODETYPE_BRANCH) {
         $this->nodetype = self::NODETYPE_BRANCH;
     }
     // Set the parent to this node
     $childnode->set_parent($this);
     // Default the key to the number of children if not provided
     if ($childnode->key === null) {
         $childnode->key = $this->children->count();
     }
     // Add the child using the navigation_node_collections add method
     $node = $this->children->add($childnode, $beforekey);
     // If added node is a category node or the user is logged in and it's a course
     // then mark added node as a branch (makes it expandable by AJAX)
     $type = $childnode->type;
     if ($type == self::TYPE_CATEGORY || isloggedin() && $type == self::TYPE_COURSE) {
         $node->nodetype = self::NODETYPE_BRANCH;
     }
     // If this node is hidden mark it's children as hidden also
     if ($this->hidden) {
         $node->hidden = true;
     }
     // Return added node (reference returned by $this->children->add()
     return $node;
 }