TreeDatabaseTiein: ezcTreeDbNestedSet
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcTreeDbNestedSet
|
ezcTreeDbNestedSet implements a tree backend which stores parent/child information with left and right values. [
source]
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.
Parents
ezcTree
|
--ezcTreeDb
|
--ezcTreeDbParentChild
|
--ezcTreeDbNestedSet
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:
From
ezcTree:
Method Summary
|
public void |
addChild(
$parentId, $childNode )
Adds the node $childNode as child of the node with ID $parentId. |
|
public static void |
create(
$dbh, $indexTableName, $store )
Creates a new ezcTreeDbNestedSet object. |
|
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 :
From
ezcTreeDb :
From
ezcTree :
Methods
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
create
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
Redefinition of
createAddEmptyNodeQuery
Creates the query to insert an empty node into the database, so that the last-inserted ID can be obtained.
Redefinition of
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
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
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
fetchSubtreeDepthFirst
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
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
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
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
setRootNode
void setRootNode(
$node )
Sets a new node as root node, this also wipes out the whole tree.
Parameters
Redefinition of
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 |
|
Last updated: Tue, 27 May 2008