## Apache Zeta Components Manual :: Docs For Class ezcTreeNode

### Tree::ezcTreeNode

### Class ezcTreeNode

ezcTreeNode represents a node in a tree.

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');
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.

Source for this file: /Tree/src/tree_node.php

### Implements interfaces:

- ezcTreeVisitable

Version: | //autogentag//

### 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 void | `injectData( $data )` Inject data.
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 |

##### Implementation of:

Method | Description
--- | ---
`ezcTreeVisitable::accept()` | Accepts the visitor.

#### 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().

#### 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.

#### injectData

void injectData( string $data )

Inject data.

Used to set the data from a data loader. Should not be used for interfacing with the tree node, since the node will not be flagged as modified by this method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$data` | string |

#### 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 |

Documentation generated by phpDocumentor 1.4.3