TreeDatabaseTiein: ezcTreeDbMaterializedPath
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcTreeDbMaterializedPath
|
ezcTreeDbMaterializedPath implements a tree backend which stores parent/child information in a path like string (such as /1/4/6/8). [
source]
The table that stores the index (configured using the $indexTableName argument of the
__construct method) should contain at least three 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 third field 'path' will contain the path string. This should be a text field. The size of the field determines the maximum depth the tree can have. 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
|
--ezcTreeDbMaterializedPath
Properties
|
string |
read/write
|
$nodeClassName
Which class is used as tree node - this class *must* inherit the ezcTreeNode class. |
|
string |
read
|
$separationChar
The character that is used to separate node IDs internally. This character can then *not* be part of a node ID. |
|
ezcTreeDbDataStore |
read
|
$store
The data store that is used for retrieving/storing data. |
Inherited Member Variables
From
ezcTreeDb:
From
ezcTree:
Method Summary
|
public ezcTreeDbMaterializedPath |
__construct(
$dbh, $indexTableName, $store, [$separationChar = '/'] )
Constructs a new ezcTreeDbMaterializedPath object. |
|
public void |
addChild(
$parentId, $childNode )
Adds the node $childNode as child of the node with ID $parentId. |
|
protected void |
addChildNodesBreadthFirst(
$list, $nodeId )
Adds the children nodes of the node with ID $nodeId to the ezcTreeNodeList $list. |
|
protected void |
checkNodeId(
$nodeId )
This method checks whether a node ID is valid to be used in a backend. |
|
public static void |
create(
$dbh, $indexTableName, $store, [$separationChar = '/'] )
Creates a new ezcTreeDbMaterializedPath 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 PDOStatement |
fetchChildRecords(
$nodeId )
Runs SQL to get all the children of the node with ID $nodeId as a PDO result set. |
|
public ezcTreeNodeList |
fetchChildren(
$nodeId )
Returns all the children of the node with ID $nodeId. |
|
protected array(int) |
fetchNodeInformation(
$nodeId )
Returns the parent id and path 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 |
fetchSubtree(
$nodeId )
Alias for fetchSubtreeDepthFirst(). |
|
public ezcTreeNodeList |
fetchSubtreeBreadthFirst(
$nodeId )
Returns the node with ID $nodeId and all its children, sorted according to the Breadth-first sorting algorithm. |
|
public ezcTreeNodeList |
fetchSubtreeDepthFirst(
$nodeId )
Returns the node with ID $nodeId and all its children, sorted according to the Depth-first sorting algorithm. |
|
public void |
fixateTransaction(
)
Fixates the transaction. |
|
public int |
getChildCount(
$nodeId )
Returns the number of direct children of the node with ID $nodeId. |
|
public int |
getChildCountRecursive(
$nodeId )
Returns the number of children of the node with ID $nodeId, recursively. |
|
public int |
getPathLength(
$nodeId )
Returns the distance from the root node to the node with ID $nodeId. |
|
public bool |
hasChildNodes(
$nodeId )
Returns whether the node with ID $nodeId has children. |
|
public bool |
isChildOf(
$childId, $parentId )
Returns whether the node with ID $childId is a direct child of the node with ID $parentId. |
|
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 bool |
isSiblingOf(
$child1Id, $child2Id )
Returns whether the nodes with IDs $child1Id and $child2Id are siblings (ie, they share the same parent). |
|
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. |
Inherited Methods
From
ezcTreeDb :
From
ezcTree :
Methods
__construct
ezcTreeDbMaterializedPath __construct(
$dbh, string
$indexTableName,
ezcTreeDbDataStore
$store, [string
$separationChar = '/'] )
Constructs a new ezcTreeDbMaterializedPath object.
The different arguments to the constructor 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.
The $separationChar argument defaults to / and is used to separate node IDs internally. This character can *not* be part of a node ID, and should be the same character that was used when creating the tree.
Just like the others, this database backend requires the index table to at least define the field 'id', which can either be a string or an integer field.
Parameters
Redefinition of
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 |
ezcTree::addChild() |
Adds the node $childNode as child of the node with ID $parentId. |
addChildNodesBreadthFirst
void addChildNodesBreadthFirst(
$list, string
$nodeId )
Adds the children nodes of the node with ID $nodeId to the ezcTreeNodeList $list.
Parameters
checkNodeId
void checkNodeId(
string
$nodeId )
This method checks whether a node ID is valid to be used in a backend.
Parameters
| Name |
Type |
Description |
$nodeId |
string |
|
Throws
| Class | Description |
ezcTreeInvalidNodeIDException |
if the node is not valid. |
Redefinition of
| Method |
Description |
ezcTree::checkNodeId() |
This method checks whether a node ID is valid to be used in a backend. |
create
void create(
$dbh, string
$indexTableName,
ezcTreeDbDataStore
$store, [string
$separationChar = '/'] )
Creates a new ezcTreeDbMaterializedPath 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.
The $separationChar argument defaults to / and is used to separate node IDs internally. This character can *not* be part of a node ID, and the same character should be used when re-opening the tree upon instantiation.
It is up to the user to create the database table and make sure it is empty.
Parameters
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
| Method |
Description |
ezcTree::delete() |
Deletes the node with ID $nodeId from the tree, including all its children. |
fetchChildRecords
PDOStatement fetchChildRecords(
string
$nodeId )
Runs SQL to get all the children of the node with ID $nodeId as a PDO result set.
Parameters
| Name |
Type |
Description |
$nodeId |
string |
|
fetchChildren
Returns all the children of the node with ID $nodeId.
Parameters
| Name |
Type |
Description |
$nodeId |
string |
|
Redefinition of
fetchNodeInformation
array(int) fetchNodeInformation(
string
$nodeId )
Returns the parent id and path the node with ID $nodeId as an array.
The format of the array is:
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
| Method |
Description |
ezcTree::fetchPath() |
Returns all the nodes in the path from the root node to the node with ID $nodeId, including those two nodes. |
fetchSubtree
Alias for fetchSubtreeDepthFirst().
Parameters
| Name |
Type |
Description |
$nodeId |
string |
|
Redefinition of
fetchSubtreeBreadthFirst
Returns the node with ID $nodeId and all its children, sorted according to the
Breadth-first sorting algorithm.
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
fixateTransaction
void fixateTransaction(
)
Fixates the transaction.
getChildCount
int getChildCount(
string
$nodeId )
Returns the number of direct children of the node with ID $nodeId.
Parameters
| Name |
Type |
Description |
$nodeId |
string |
|
Redefinition of
getChildCountRecursive
int getChildCountRecursive(
string
$nodeId )
Returns the number of children of the node with ID $nodeId, recursively.
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
hasChildNodes
bool hasChildNodes(
string
$nodeId )
Returns whether the node with ID $nodeId has children.
Parameters
| Name |
Type |
Description |
$nodeId |
string |
|
Redefinition of
isChildOf
bool isChildOf(
string
$childId, string
$parentId )
Returns whether the node with ID $childId is a direct child of the node with ID $parentId.
Parameters
| Name |
Type |
Description |
$childId |
string |
|
$parentId |
string |
|
Redefinition of
| Method |
Description |
ezcTree::isChildOf() |
Returns whether the node with ID $childId is a direct child of the node with ID $parentId. |
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 |
ezcTree::isDescendantOf() |
Returns whether the node with ID $childId is a direct or indirect child of the node with ID $parentId. |
isSiblingOf
bool isSiblingOf(
string
$child1Id, string
$child2Id )
Returns whether the nodes with IDs $child1Id and $child2Id are siblings (ie, they share the same parent).
Parameters
| Name |
Type |
Description |
$child1Id |
string |
|
$child2Id |
string |
|
Redefinition of
| Method |
Description |
ezcTree::isSiblingOf() |
Returns whether the nodes with IDs $child1Id and $child2Id are siblings (ie, they share the same parent). |
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 |
ezcTree::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
Redefinition of
Last updated: Wed, 18 Jun 2008