cms_tree View code

A Simple PHP Tree class that allows storing associative data along with each node.

package

CMS

author

Robert Campbell

copyright

Copyright (c) 2010, Robert Campbell calguy1000@cmsmadesimple.org

since 1.9

Methods

__construct(string $key = '', mixed $value = '') 

Construct a new tree, or node of a tree.

Arguments

string $key

An optional key for a tag

mixed $value

An optional value for the tag.

find_by_tag(string $tag_name, mixed $value, boolean $case_insensitive = FALSE) : \cms_tree

Find a tree node given a specfied tag and value.

Arguments

string $tag_name

The tag name to search for

mixed $value

The tag value to search for

boolean $case_insensitive

Wether the value should be treated as case insensitive.

Response

\cms_tree

or null on failure.

has_children() : boolean

Test if this node has children.

Response

boolean

set_tag(string $key, mixed $value) 

Set a tag value into this node

Arguments

string $key

Tag name

mixed $value

Tag value

get_tag(string $key) : mixed

Retrieve a tag for this node.

Arguments

string $key

The tag name

Response

mixed

The tag value, or null

remove_node(\cms_tree &$node, boolean $search_children = false) : boolean

Remove the specified node from the tree.

Search through the children of this node (and optionally recursively through the tree) for the specified node. If found, remove it.

Use this method with caution, as it is very easy to break your tree, corrupt memory and have tree nodes hanging out there with no parents.

Arguments

\cms_tree $node

Reference to the node to be removed.

boolean $search_children

Wether to recursively search children.

Response

boolean

remove() : boolean

Remove this node

This is a convenience method that calls remove_node on the current object.

Response

boolean

get_parent() : \cms_tree

Get a reference to the parent node.

Response

\cms_tree

Reference to the parent node, or null.

getParent() : \cms_tree

Get a reference to the parent node.

deprecated

Response

\cms_tree

Reference to the parent node, or null.

add_node(\cms_tree &$node) 

Add the specified node as a child to this node.

Arguments

\cms_tree $node

The node to add

count_children() : integer

Count the number of direct children to this node.

Response

integer

count_siblings() : integer

Count the number of siblings that this node has.

Response

integer

count_nodes() : integer

Count the total number of all nodes, including myself.

Response

integer

get_level() : integer

Find the depth of the current node.

This method counts all of the parents in the tree until there are no more parents.

Response

integer

get_children() : \an

Return the children of this node.

Response

\an

array of cms_tree objects, or null if there are no children.