Apache Zeta Components Manual :: File Source for tree_node_list_iterator.php
Source for file tree_node_list_iterator.php
Documentation is available at tree_node_list_iterator.php
* File containing the ezcTreeNodeListIterator class.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @version //autogentag//
* ezcTreeNodeListIterator implements an iterator over an ezcTreeNodeList.
* 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
* // fetch all the nodes in a subtree as an ezcNodeList
* $nodeList = $tree->fetchSubtree( 'pan' );
* foreach ( new ezcTreeNodeListIterator( $tree, $nodeList ) as $nodeId => $data )
* // do something with the node ID and data - data is fetched on
* 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.
* // fetch all the nodes in a subtree as an ezcNodeList
* $nodeList = $tree->fetchSubtree( 'Uranus' );
* // instantiate an iterator with pre-fetching enabled
* foreach ( new ezcTreeNodeListIterator( $tree, $nodeList, true ) as $nodeId => $data )
* // do something with the node ID and data - data is fetched when
* // the iterator is instatiated.
* @version //autogentag//
* Holds the nodes of this list.
* @var array(ezcTreeNode)
* Holds a link to the tree that contains the nodes that are iterated over.
* This is used for accessing the data store so that data can be fetched
* Constructs a new ezcTreeNodeListIterator object over $nodeList.
* The $tree argument is used so that data can be fetched on-demand.
* @param ezcTreeNodeList $nodeList
public function __construct( ezcTree $tree, ezcTreeNodeList $nodeList, $prefetch =
false )
$this->tree->store->fetchDataForNodes( $nodeList );
$this->nodeList =
$nodeList->nodes;
* Rewinds the internal pointer back to the start of the nodelist.
reset( $this->nodeList );
if ( count( $this->nodeList ) )
* Returns the node ID of the current node.
return key( $this->nodeList );
* Returns the data belonging to the current node, and fetches the data in
* case on-demand fetching is required.
$node =
current( $this->nodeList );
* Advances the internal pointer to the next node in the nodelist.
$nextElem =
next( $this->nodeList );
if ( $nextElem ===
false )
* Returns whether the internal pointer is still valid.
* It returns false when the end of list has been reached.