CMS Made Simple API

cms_tree
in package

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

Tags
author

Robert Campbell

copyright

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

since
1.9

Table of Contents

Methods

__construct()  : mixed
Construct a new tree, or node of a tree.
add_node()  : mixed
Add the specified node as a child to this node.
count_children()  : int
Count the number of direct children to this node.
count_nodes()  : int
Count the total number of all nodes, including myself.
count_siblings()  : int
Count the number of siblings that this node has.
find_by_tag()  : cms_tree
Find a tree node given a specfied tag and value.
get_children()  : an
Return the children of this node.
get_level()  : int
Find the depth of the current node.
get_parent()  : cms_tree
Get a reference to the parent node.
get_tag()  : mixed
Retrieve a tag for this node.
getParent()  : cms_tree
Get a reference to the parent node.
has_children()  : bool
Test if this node has children.
remove()  : bool
Remove this node
set_tag()  : mixed
Set a tag value into this node
remove_node()  : bool
Remove the specified node from the tree.

Methods

__construct()

Construct a new tree, or node of a tree.

public __construct([string $key = '' ][, mixed $value = '' ]) : mixed
Parameters
$key : string = ''

An optional key for a tag

$value : mixed = ''

An optional value for the tag.

add_node()

Add the specified node as a child to this node.

public add_node(cms_tree &$node) : mixed
Parameters
$node : cms_tree

The node to add

count_children()

Count the number of direct children to this node.

public count_children() : int
Return values
int

count_nodes()

Count the total number of all nodes, including myself.

public count_nodes() : int
Return values
int

count_siblings()

Count the number of siblings that this node has.

public count_siblings() : int
Return values
int

find_by_tag()

Find a tree node given a specfied tag and value.

public & find_by_tag(string $tag_name, mixed $value[, bool $case_insensitive = FALSE ]) : cms_tree
Parameters
$tag_name : string

The tag name to search for

$value : mixed

The tag value to search for

$case_insensitive : bool = FALSE

Wether the value should be treated as case insensitive.

Return values
cms_tree

or null on failure.

get_children()

Return the children of this node.

public & get_children() : an
Return values
an

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

get_level()

Find the depth of the current node.

public get_level() : int

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

Return values
int

get_parent()

Get a reference to the parent node.

public & get_parent() : cms_tree
Tags
since
2.0
Return values
cms_tree

Reference to the parent node, or null.

get_tag()

Retrieve a tag for this node.

public & get_tag(string $key) : mixed
Parameters
$key : string

The tag name

Return values
mixed

The tag value, or null

getParent()

Get a reference to the parent node.

public & getParent() : cms_tree
Return values
cms_tree

Reference to the parent node, or null.

has_children()

Test if this node has children.

public has_children() : bool
Return values
bool

remove()

Remove this node

public remove() : bool

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

Return values
bool

set_tag()

Set a tag value into this node

public set_tag(string $key, mixed $value) : mixed
Parameters
$key : string

Tag name

$value : mixed

Tag value

remove_node()

Remove the specified node from the tree.

protected remove_node(cms_tree &$node[, bool $search_children = false ]) : bool

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.

Parameters
$node : cms_tree

Reference to the node to be removed.

$search_children : bool = false

Wether to recursively search children.

Return values
bool

        
On this page

Search results