Apache Zeta Components Manual :: File Source for tree_node_list.php
Source for file tree_node_list.php
Documentation is available at tree_node_list.php
* File containing the ezcTreeNodeList 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//
* ezcTreeNodeList represents a lists of nodes.
* The nodes in the list can be accessed through an array as this class
* implements the ArrayAccess SPL interface. The array is indexed based on the
* // Create a list with two elements
* $list = new ezcTreeNodeList;
* $list->addNode( new ezcTreeNode( $tree, 'Leo' ) );
* $list->addNode( new ezcTreeNode( $tree, 'Virgo' ) );
* // Retrieve the list's size
* echo $list->size, "\n"; // prints 2
* // Find a node in the list
* $node = $list['Virgo'];
* // Add nodes in an alternative way
* $list['Libra'] = new ezcTreeNode( $tree, 'Libra' );
* // Remove a node from the list
* // Checking if a node exists
* if ( isset( $list['Scorpius'] ) )
* // do something if it exists
* // Use the associated data store to fetch the data for all nodes at once
* $list->fetchDataForNodes();
* @see ezcTreeNodeListIterator
* @property-read string $size
* The number of nodes in the list.
* @property-read array(string=>ezcTreeNode) $nodes
* The nodes belonging to this list.
* @version //autogentag//
* Holds the nodes of this list.
* @var array(ezcTreeNode)
* Constructs a new ezcTreeNodeList object.
* Returns the value of the property $name.
* @throws ezcBasePropertyNotFoundException if the property does not exist.
public function __get( $name )
return count( $this->nodes );
* Sets the property $name to $value.
* @throws ezcBasePropertyNotFoundException if the property does not exist.
* @throws ezcBasePropertyPermissionException if a read-only property is
public function __set( $name, $value )
* Returns whether a node with the ID $nodeId exists in the list.
* This method is part of the SPL ArrayAccess interface.
public function offsetExists( $nodeId )
* Returns the node with the ID $nodeId.
* This method is part of the SPL ArrayAccess interface.
public function offsetGet( $nodeId )
return $this->nodes[$nodeId];
* Adds a new node with node ID $nodeId to the list.
* This method is part of the SPL ArrayAccess interface.
* @throws ezcTreeInvalidClassException if the data to be set as array
* element is not an instance of ezcTreeNode
* @throws ezcTreeIdsDoNotMatchException if the array index $nodeId does not
* match the tree node's ID that is stored in the $data object
* @param ezcTreeNode $data
public function offsetSet( $nodeId, $data )
if ( $data->id !==
$nodeId )
* Removes the node with ID $nodeId from the list.
* This method is part of the SPL ArrayAccess interface.
public function offsetUnset( $nodeId )
unset
( $this->nodes[$nodeId] );
* Adds the node $node to the list.
* @param ezcTreeNode $node
public function addNode( ezcTreeNode $node )
$this->nodes[$node->id] =
$node;
* Fetches data for all nodes in the node list.
// We need to use a little trick to get to the tree object. We can do
// that through ezcTreeNode objects that are part of this list. We
// can't do that when the list is empty. In that case we just return.
if ( count( $this->nodes ) ===
0 )
// Find a node in the list
// Grab the tree and use it to fetch data for all nodes from the store
$tree->store->fetchDataForNodes( $this );