Zeta Components - high quality PHP components

Zeta Components Manual :: Docs For Class ezcTreeDbNestedSet

TreeDatabaseTiein::ezcTreeDbNestedSet

Class ezcTreeDbNestedSet

ezcTreeDbNestedSet implements a tree backend which stores parent/child information with left and right values.

The table that stores the index (configured using the $indexTableName argument of the __construct method) should contain at least four fields. The first one 'id' will contain the node's ID, the second one 'parent_id' the ID of the node's parent. Both fields should be of the same database field type. Supported field types are either integer or a string type. The other two fields "lft" and "rgt" will store the left and right values that the algorithm requires. These two fields should be of an integer type. In order to use auto-generated IDs, the 'id' field needs to be an auto-incrementing integer field, by using either an auto-increment field, or a sequence.

Source for this file: /TreeDatabaseTiein/src/backends/db_nested_set.php

ezcTree
   |
   --ezcTreeDb
      |
      --ezcTreeDbParentChild
         |
         --ezcTreeDbNestedSet
Version:   //autogentag//

Properties

string read/write $nodeClassName
Which class is used as tree node - this class *must* inherit the ezcTreeNode class.
ezcTreeDbDataStore read $store
The data store that is used for retrieving/storing data.

Inherited Member Variables

From ezcTreeDb
protected ezcTreeDb::$dbh
protected ezcTreeDb::$indexTableName
From ezcTree
protected ezcTree::$inTransaction
protected ezcTree::$inTransactionCommit
protected ezcTree::$properties

Method Summary

public static void create( $dbh , $indexTableName , $store )
Creates a new ezcTreeDbNestedSet object.
public void addChild( $parentId , $childNode )
Adds the node $childNode as child of the node with ID $parentId.
protected ezcQueryInsert createAddEmptyNodeQuery( )
Creates the query to insert an empty node into the database, so that the last-inserted ID can be obtained.
public void delete( $nodeId )
Deletes the node with ID $nodeId from the tree, including all its children.
protected array(int) fetchNodeInformation( $nodeId )
Returns the left, right and width values for the node with ID $nodeId as an array.
public ezcTreeNodeList fetchPath( $nodeId )
Returns all the nodes in the path from the root node to the node with ID $nodeId, including those two nodes.
public ezcTreeNodeList fetchSubtreeDepthFirst( $nodeId )
Returns the node with ID $nodeId and all its children, sorted according to the Depth-first sorting algorithm.
public int getPathLength( $nodeId )
Returns the distance from the root node to the node with ID $nodeId.
public bool isDescendantOf( $childId , $parentId )
Returns whether the node with ID $childId is a direct or indirect child of the node with ID $parentId.
public void move( $nodeId , $targetParentId )
Moves the node with ID $nodeId as child to the node with ID $targetParentId.
public void setRootNode( $node )
Sets a new node as root node, this also wipes out the whole tree.
protected void updateNestedValuesForSubtreeAddition( $right , $width , [ $excludedIds = array()] )
Updates the left and right values of the nodes that are added while adding a whole subtree as child of a node.
protected void updateNestedValuesForSubtreeDeletion( $right , $width )
Updates the left and right values in case a subtree is deleted.

Inherited Methods

From ezcTreeDbParentChild
public void ezcTreeDbParentChild::addChild()
Adds the node $childNode as child of the node with ID $parentId.
protected void ezcTreeDbParentChild::addChildNodesBreadthFirst()
Adds the children nodes of the node with ID $nodeId to the ezcTreeNodeList $list.
protected void ezcTreeDbParentChild::countChildNodes()
Adds the number of children with for the node with ID $nodeId nodes to $count, recursively.
public static void ezcTreeDbParentChild::create()
Creates a new ezcTreeDbParentChild object.
protected ezcQueryInsert ezcTreeDbParentChild::createAddEmptyNodeQuery()
Creates the query to insert an empty node into the database, so that the last-inserted ID can be obtained.
public void ezcTreeDbParentChild::delete()
Deletes the node with ID $nodeId from the tree, including all its children.
protected PDOStatement ezcTreeDbParentChild::fetchChildRecords()
Runs SQL to get all the children of the node with ID $nodeId as a PDO result set.
public ezcTreeNodeList ezcTreeDbParentChild::fetchChildren()
Returns all the children of the node with ID $nodeId.
public ezcTreeNodeList ezcTreeDbParentChild::fetchPath()
Returns all the nodes in the path from the root node to the node with ID $nodeId, including those two nodes.
public ezcTreeNodeList ezcTreeDbParentChild::fetchSubtree()
Alias for fetchSubtreeDepthFirst().
public ezcTreeNodeList ezcTreeDbParentChild::fetchSubtreeBreadthFirst()
Returns the node with ID $nodeId and all its children, sorted according to the Breadth-first sorting algorithm.
public ezcTreeNodeList ezcTreeDbParentChild::fetchSubtreeDepthFirst()
Returns the node with ID $nodeId and all its children, sorted according to the Depth-first sorting algorithm.
public void ezcTreeDbParentChild::fixateTransaction()
Fixates the transaction.
public int ezcTreeDbParentChild::getChildCount()
Returns the number of direct children of the node with ID $nodeId.
public int ezcTreeDbParentChild::getChildCountRecursive()
Returns the number of children of the node with ID $nodeId, recursively.
public int ezcTreeDbParentChild::getPathLength()
Returns the distance from the root node to the node with ID $nodeId.
public bool ezcTreeDbParentChild::hasChildNodes()
Returns whether the node with ID $nodeId has children.
public bool ezcTreeDbParentChild::isChildOf()
Returns whether the node with ID $childId is a direct child of the node with ID $parentId.
public bool ezcTreeDbParentChild::isDescendantOf()
Returns whether the node with ID $childId is a direct or indirect child of the node with ID $parentId.
public bool ezcTreeDbParentChild::isSiblingOf()
Returns whether the nodes with IDs $child1Id and $child2Id are siblings (ie, they share the same parent).
public void ezcTreeDbParentChild::move()
Moves the node with ID $nodeId as child to the node with ID $targetParentId.
public void ezcTreeDbParentChild::setRootNode()
Sets a new node as root node, this also wipes out the whole tree.
From ezcTreeDb
public ezcTreeDb ezcTreeDb::__construct()
Constructs a new ezcTreeDb object.
protected abstract ezcQueryInsert ezcTreeDb::createAddEmptyNodeQuery()
Creates the query to insert an empty node into the database, so that the last-inserted ID can be obtained.
protected ezcQuery ezcTreeDb::createAddNodeQuery()
Creates the query to insert/update an empty node in the database.
public ezcTreeNode ezcTreeDb::fetchParent()
Returns the parent node of the node with ID $id.
protected integer ezcTreeDb::generateNodeID()
This method generates the next node ID.
protected string ezcTreeDb::getParentId()
Returns the ID of parent of the node with ID $childId.
public ezcTreeNode ezcTreeDb::getRootNode()
Returns the root node.
public bool ezcTreeDb::nodeExists()
Returns whether the node with ID $id exists as tree node.
From ezcTree
public void ezcTree::accept()
Implements the accept method for visiting.
public abstract void ezcTree::addChild()
Adds the node $childNode as child of the node with ID $parentId.
protected void ezcTree::addTransactionItem()
Adds a new transaction item to the list.
public void ezcTree::beginTransaction()
Starts an transaction in which all tree modifications are queued until the transaction is committed with the commit() method.
protected void ezcTree::checkNodeId()
This method checks whether a node ID is valid to be used in a backend.
public void ezcTree::commit()
Commits the transaction by running the stored instructions to modify the tree structure.
public static void ezcTree::copy()
Copies the tree in $from to the empty tree in $to.
public ezcTreeNode ezcTree::createNode()
Creates a new tree node with node ID $nodeId and $data.
public abstract void ezcTree::delete()
Deletes the node with ID $nodeId from the tree, including all its children.
public abstract ezcTreeNodeList ezcTree::fetchChildren()
Returns all the children of the node with ID $nodeId.
public ezcTreeNode ezcTree::fetchNodeById()
Returns the node identified by the ID $nodeId.
public abstract ezcTreeNode ezcTree::fetchParent()
Returns the parent node of the node with ID $nodeId.
public abstract ezcTreeNodeList ezcTree::fetchPath()
Returns all the nodes in the path from the root node to the node with ID $nodeId, including those two nodes.
public abstract ezcTreeNodeList ezcTree::fetchSubtree()
Alias for fetchSubtreeDepthFirst().
public abstract ezcTreeNodeList ezcTree::fetchSubtreeBreadthFirst()
Returns the node with ID $nodeId and all its children, sorted according to the Breadth-first sorting algorithm.
public abstract ezcTreeNodeList ezcTree::fetchSubtreeDepthFirst()
Returns the node with ID $nodeId and all its children, sorted according to the Depth-first sorting algorithm.
protected abstract integer ezcTree::generateNodeID()
This method generates the next node ID.
public abstract int ezcTree::getChildCount()
Returns the number of direct children of the node with ID $nodeId.
public abstract int ezcTree::getChildCountRecursive()
Returns the number of children of the node with ID $nodeId, recursively.
public abstract int ezcTree::getPathLength()
Returns the distance from the root node to the node with ID $nodeId.
public abstract ezcTreeNode ezcTree::getRootNode()
Returns the root node.
public abstract bool ezcTree::hasChildNodes()
Returns whether the node with ID $nodeId has children.
public bool ezcTree::inTransaction()
Returns whether we are currently in a transaction or not
public bool ezcTree::inTransactionCommit()
Returns whether we are currently in a transaction commit state or not
public abstract bool ezcTree::isChildOf()
Returns whether the node with ID $childId is a direct child of the node with ID $parentId.
public abstract bool ezcTree::isDescendantOf()
Returns whether the node with ID $childId is a direct or indirect child of the node with ID $parentId.
public abstract bool ezcTree::isSiblingOf()
Returns whether the nodes with IDs $child1Id and $child2Id are siblings (ie, they share the same parent).
public abstract void ezcTree::move()
Moves the node with ID $nodeId as child to the node with ID $targetParentId.
public abstract bool ezcTree::nodeExists()
Returns whether the node with ID $nodeId exists.
public void ezcTree::rollback()
Rolls back the transaction by clearing all stored instructions.
public abstract void ezcTree::setRootNode()
Sets a new node as root node, this also wipes out the whole tree.

Methods

create

static void create( $dbh , string $indexTableName , ezcTreeDbDataStore $store )

Creates a new ezcTreeDbNestedSet object.

The different arguments to the method configure which database connection ($dbh) is used to access the database and the $indexTableName argument which table is used to retrieve the relation data from. The $store argument configure which data store is used with this tree.

It is up to the user to create the database table and make sure it is empty.

Parameters:
Name Type Description
$dbh ezcDbHandler
$indexTableName string
$store ezcTreeDbDataStore
Redefinition of:
Method Description
ezcTreeDbParentChild::create() Creates a new ezcTreeDbParentChild object.

addChild

void addChild( string $parentId , $childNode )

Adds the node $childNode as child of the node with ID $parentId.

Parameters:
Name Type Description
$parentId string
$childNode ezcTreeNode
Redefinition of:
Method Description
ezcTreeDbParentChild::addChild() Adds the node $childNode as child of the node with ID $parentId.

createAddEmptyNodeQuery

ezcQueryInsert createAddEmptyNodeQuery( )

Creates the query to insert an empty node into the database, so that the last-inserted ID can be obtained.

Redefinition of:
Method Description
ezcTreeDbParentChild::createAddEmptyNodeQuery() Creates the query to insert an empty node into the database, so that the last-inserted ID can be obtained.

delete

void delete( string $nodeId )

Deletes the node with ID $nodeId from the tree, including all its children.

Parameters:
Name Type Description
$nodeId string
Redefinition of:
Method Description
ezcTreeDbParentChild::delete() Deletes the node with ID $nodeId from the tree, including all its children.

fetchNodeInformation

array(int) fetchNodeInformation( string $nodeId )

Returns the left, right and width values for the node with ID $nodeId as an array.

The format of the array is:

  • 0: left value
  • 1: right value
  • 2: width value (right - left + 1)
Parameters:
Name Type Description
$nodeId string

fetchPath

ezcTreeNodeList fetchPath( string $nodeId )

Returns all the nodes in the path from the root node to the node with ID $nodeId, including those two nodes.

Parameters:
Name Type Description
$nodeId string
Redefinition of:
Method Description
ezcTreeDbParentChild::fetchPath() Returns all the nodes in the path from the root node to the node with ID $nodeId, including those two nodes.

fetchSubtreeDepthFirst

ezcTreeNodeList fetchSubtreeDepthFirst( string $nodeId )

Returns the node with ID $nodeId and all its children, sorted according to the Depth-first sorting algorithm.

Parameters:
Name Type Description
$nodeId string
Redefinition of:
Method Description
ezcTreeDbParentChild::fetchSubtreeDepthFirst() Returns the node with ID $nodeId and all its children, sorted according to the Depth-first sorting algorithm.

getPathLength

int getPathLength( string $nodeId )

Returns the distance from the root node to the node with ID $nodeId.

Parameters:
Name Type Description
$nodeId string
Redefinition of:
Method Description
ezcTreeDbParentChild::getPathLength() Returns the distance from the root node to the node with ID $nodeId.

isDescendantOf

bool isDescendantOf( string $childId , string $parentId )

Returns whether the node with ID $childId is a direct or indirect child of the node with ID $parentId.

Parameters:
Name Type Description
$childId string
$parentId string
Redefinition of:
Method Description
ezcTreeDbParentChild::isDescendantOf() Returns whether the node with ID $childId is a direct or indirect child of the node with ID $parentId.

move

void move( string $nodeId , string $targetParentId )

Moves the node with ID $nodeId as child to the node with ID $targetParentId.

Parameters:
Name Type Description
$nodeId string
$targetParentId string
Redefinition of:
Method Description
ezcTreeDbParentChild::move() Moves the node with ID $nodeId as child to the node with ID $targetParentId.

setRootNode

void setRootNode( $node )

Sets a new node as root node, this also wipes out the whole tree.

Parameters:
Name Type Description
$node ezcTreeNode
Redefinition of:
Method Description
ezcTreeDbParentChild::setRootNode() Sets a new node as root node, this also wipes out the whole tree.

updateNestedValuesForSubtreeAddition

void updateNestedValuesForSubtreeAddition( int $right , int $width , [array(string) $excludedIds = array()] )

Updates the left and right values of the nodes that are added while adding a whole subtree as child of a node.

The method does not update nodes where the IDs are in the $excludedIds list.

Parameters:
Name Type Description
$right int
$width int
$excludedIds array(string)

updateNestedValuesForSubtreeDeletion

void updateNestedValuesForSubtreeDeletion( int $right , int $width )

Updates the left and right values in case a subtree is deleted.

Parameters:
Name Type Description
$right int
$width int
Documentation generated by phpDocumentor 1.4.3