Path

ez components / documentation / api reference / trunk / tree


eZ Components trunk

Tree: ezcTreeNodeListIterator

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

Class: ezcTreeNodeListIterator

ezcTreeNodeListIterator implements an iterator over an ezcTreeNodeList. [source]

Implemented Interfaces

  • Iterator (internal interface)

The iterator is instantiated with both an implementation of an ezcTree and an ezcTreeNodeList object. It can be used to iterate over all the nodes in a list.
Example:
 1.  <?php
 2.      // fetch all the nodes in a subtree as an ezcNodeList
 3.      $nodeList $tree->fetchSubtree'pan' );
 4.      foreach new ezcTreeNodeListIterator$tree$nodeList as $nodeId => $data )
 5.      {
 6.          // do something with the node ID and data - data is fetched on
 7.          // demand
 8.      }
 9.  ?>
Data for the nodes in the node lists is fetched on demand, unless the "prefetch" argument is set to true. In that case the iterator will fetch the data when the iterator is instantiated. This reduces the number of queries made for database and persistent object based data stores, but increases memory usage.
Example:
 1.  <?php
 2.      // fetch all the nodes in a subtree as an ezcNodeList
 3.      $nodeList $tree->fetchSubtree'Uranus' );
 4.      // instantiate an iterator with pre-fetching enabled
 5.      foreach new ezcTreeNodeListIterator$tree$nodeListtrue as $nodeId => $data )
 6.      {
 7.          // do something with the node ID and data - data is fetched when
 8.          // the iterator is instatiated.
 9.      }
10.  ?>

Method Summary

public ezcTreeNodeListIterator __construct( $tree, $nodeList, [$prefetch = false] )
Constructs a new ezcTreeNodeListIterator object over $nodeList.
public mixed current( )
Returns the data belonging to the current node, and fetches the data in case on-demand fetching is required.
public string key( )
Returns the node ID of the current node.
public void next( )
Advances the internal pointer to the next node in the nodelist.
public void rewind( )
Rewinds the internal pointer back to the start of the nodelist.
public bool valid( )
Returns whether the internal pointer is still valid.

Methods

__construct

ezcTreeNodeListIterator __construct( ezcTree $tree, ezcTreeNodeList $nodeList, [bool $prefetch = false] )
Constructs a new ezcTreeNodeListIterator object over $nodeList.
The $tree argument is used so that data can be fetched on-demand.

Parameters

Name Type Description
$tree ezcTree  
$nodeList ezcTreeNodeList  
$prefetch bool  

current

mixed current( )
Returns the data belonging to the current node, and fetches the data in case on-demand fetching is required.

key

string key( )
Returns the node ID of the current node.

next

void next( )
Advances the internal pointer to the next node in the nodelist.

rewind

void rewind( )
Rewinds the internal pointer back to the start of the nodelist.

valid

bool valid( )
Returns whether the internal pointer is still valid.
It returns false when the end of list has been reached.

Last updated: Mon, 21 Dec 2009