Path

ez components / documentation / api reference / trunk / tree


eZ Components trunk

Tree: ezcTreeNode

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcTreeNode

ezcTreeNode represents a node in a tree. [source]

Implemented Interfaces

The methods that operate on nodes (fetchChildren, fetchPath, ..., isSiblingOf) are all marshalled to calls on the tree (that is stored in the $tree private variable) itself.
Example:
 1.  <?php
 2.      // Creates a new node with ID 'O' and as data 'Oxygen'
 3.      $node new ezcTreeNode$this->tree'O''Oxygen' );
 4.  
 5.      // Adds a node as child element to another already create node in a tree
 6.      $parentNode->addChild$node );
 7.  ?>
To use your own implementation of tree nodes, you can override the class that is used by the tree by setting the nodeClassName property of the ezcTree class. The class must inherit from this class though.

Properties

mixed read/write  $data
The data belonging to a node
bool read/write  $dataFetched
Whether the data for this node has been fetched. Should *only* be modified by data store implementations.
bool read/write  $dataStored
Whether the data for this node has been stored. Should *only* be modified by data store implementations.
string read  $id
The ID that uniquely identifies a node
ezcTree read  $tree
The tree object that this node belongs to

Method Summary

public ezcTreeNode __construct( $tree, $nodeId, $data )
Constructs a new ezcTreeNode object with ID $nodeId on tree $tree.
public void accept( $visitor )
Implements the accept method for visiting.
public void addChild( $node )
Adds the node $node as child of the current node to the tree.
public ezcTreeNodeList fetchChildren( )
Returns all the children of this node.
public ezcTreeNode fetchParent( )
Returns the parent node of this node.
public ezcTreeNodeList fetchPath( )
Returns all the nodes in the path from the root node to this node.
public ezcTreeNodeList fetchSubtree( )
Alias for fetchSubtreeDepthFirst().
public ezcTreeNodeList fetchSubtreeBreadthFirst( )
Returns this node and all its children, sorted accoring to the Breadth-first sorting algorithm.
public ezcTreeNodeList fetchSubtreeDepthFirst( )
Returns this node and all its children, sorted according to the Depth-first sorting algorithm.
public int getChildCount( )
Returns the number of direct children of this node.
public int getChildCountRecursive( )
Returns the number of children of this node, recursively iterating over the children.
public int getPathLength( )
Returns the distance from the root node to this node.
public bool hasChildNodes( )
Returns whether this node has children.
public bool isChildOf( $parentNode )
Returns whether this node is a direct child of the $parentNode node.
public bool isDescendantOf( $parentNode )
Returns whether this node is a direct or indirect child of the $parentNode node.
public bool isSiblingOf( $child2Node )
Returns whether this node, and the $child2Node node are are siblings (ie, they share the same parent).

Methods

__construct

ezcTreeNode __construct( ezcTree $tree, string $nodeId, mixed $data )
Constructs a new ezcTreeNode object with ID $nodeId on tree $tree.
If a third argument is specified it is used as data for the new node.

Parameters

Name Type Description
$tree ezcTree  
$nodeId string  
$data mixed  

accept

void accept( ezcTreeVisitor $visitor )
Implements the accept method for visiting.

Parameters

Name Type Description
$visitor ezcTreeVisitor  

addChild

void addChild( ezcTreeNode $node )
Adds the node $node as child of the current node to the tree.

Parameters

Name Type Description
$node ezcTreeNode  

fetchChildren

ezcTreeNodeList fetchChildren( )
Returns all the children of this node.

fetchParent

ezcTreeNode fetchParent( )
Returns the parent node of this node.

fetchPath

ezcTreeNodeList fetchPath( )
Returns all the nodes in the path from the root node to this node.

fetchSubtree

ezcTreeNodeList fetchSubtree( )
Alias for fetchSubtreeDepthFirst().

See also:

ezcTreeNode::fetchSubtreeDepthFirst().


fetchSubtreeBreadthFirst

ezcTreeNodeList fetchSubtreeBreadthFirst( )
Returns this node and all its children, sorted accoring to the Breadth-first sorting algorithm.

fetchSubtreeDepthFirst

ezcTreeNodeList fetchSubtreeDepthFirst( )
Returns this node and all its children, sorted according to the Depth-first sorting algorithm.

getChildCount

int getChildCount( )
Returns the number of direct children of this node.

getChildCountRecursive

int getChildCountRecursive( )
Returns the number of children of this node, recursively iterating over the children.

getPathLength

int getPathLength( )
Returns the distance from the root node to this node.

hasChildNodes

bool hasChildNodes( )
Returns whether this node has children.

isChildOf

bool isChildOf( ezcTreeNode $parentNode )
Returns whether this node is a direct child of the $parentNode node.

Parameters

Name Type Description
$parentNode ezcTreeNode  

isDescendantOf

bool isDescendantOf( ezcTreeNode $parentNode )
Returns whether this node is a direct or indirect child of the $parentNode node.

Parameters

Name Type Description
$parentNode ezcTreeNode  

isSiblingOf

bool isSiblingOf( ezcTreeNode $child2Node )
Returns whether this node, and the $child2Node node are are siblings (ie, they share the same parent).

Parameters

Name Type Description
$child2Node ezcTreeNode  

Last updated: Mon, 21 Dec 2009