Home » Database » DB_NestedSet » Manual
With this package, one can easily create trees with infinite depth inside a relational database.
Introduction
Introduction – Introduction to DB_NestedSet
Overview
With this package, one can easily create trees with infinite depth inside a relational database. The package provides a way to
- create/update/delete nodes
- query nodes, trees and subtrees
- copy (clone) nodes, trees and subtrees
- move nodes, trees and subtrees
- etc.
An example
Creates some root and subnodes
In this example, one rootnode and two subnodes are created, saved to the database and displayed.
<?php
require_once 'DB/NestedSet.php';
require_once 'DB/NestedSet/Output.php';
require_once 'HTML/Menu.php';
$DatabasePointer = mysql_connect("localhost", "user", "pwd");
mysql_select_db("database", $DatabasePointer);
$dsn = 'mysql://user:pwd@localhost/database';
// needed colums in table:
$params = array(
'id' => 'id',
'parent_id' => 'rootid',
'left_id' => 'l',
'right_id' => 'r',
'order_num' => 'norder',
'level' => 'level',
'name' => 'name',
);
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->setAttr(array(
'node_table' => 'nested_set',
'lock_table' => 'nested_set_locks',
'secondarySort' => 'name',
)
);
$parent = $nestedSet->createRootNode(array('name' =>'root 1'), false, true);
$nestedSet->createSubNode($parent, array('name' => 'node 1.1'));
$nestedSet->createSubNode($parent, array('name' =>'node 1.2'));
$data = $nestedSet->getAllNodes(true);
foreach ($data as $id => $node) {
$data[$id]['url'] = 'index.php?nodeID=' . $node['id'];
}
$params = array(
'structure' => $data,
'titleField' => 'name',
'urlField' => 'url');
$output =& DB_NestedSet_Output::factory($params, 'Menu');
$structure = $output->returnStructure();
$menu = & new HTML_Menu($structure, 'sitemap');
$menu->forceCurrentUrl($currentUrl);
$menu->show();
?>
DB_NestedSet::addListener
DB_NestedSet::addListener() – Add an event listener
Synopsis
require_once 'DB/NestedSet.php';
string
DB_NestedSet::addListener
(
string
$event
,
&$listener
,
string
$listener
)
Description
Adds an event listener and returns an ID for it
Known events are
nodeCreate
nodeDelete
nodeUpdate
nodeCopy
nodeLoad
Parameter
-
string
$event -
The event name
-
string
$listener -
The listener object
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Add Listener
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->AddListener("nodeCreate", "listener");
?>
DB_NestedSet::apiVersion
DB_NestedSet::apiVersion() – apiVersion
Synopsis
require_once 'DB/NestedSet.php';
void
DB_NestedSet::apiVersion
(
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Get API-version
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->apiVersion();
?>
DB_NestedSet::convertTreeModel
DB_NestedSet::convertTreeModel() – Convert a <1.3 tree into a 1.3 tree format
Synopsis
require_once 'DB/NestedSet.php';
bool
DB_NestedSet::convertTreeModel
(
&$orig
,
&$copy
,
integer
$_parent
= false
,
object
$
)
Description
This will convert the tree into a format needed for some new features in 1.3. Your <1.3 tree will still work without converting but some new features like preorder sorting won't work as expected.
Usage:
- Create a new node table (tb_nodes2) from the current node table (tb_nodes1) (only copy the structure).
- Create a nested set instance of the 'old' set (NeSe1) and one of the new set (NeSe2)
- Now you have 2 identical objects where only node_table differs
- Call DB_NestedSet::convertTreeModel(&$orig, &$copy);
- After that you have a cleaned up copy of tb_nodes1 inside tb_nodes2
Parameter
-
&$orig
-
&$copy
-
integer
$_parent -
ID of the parent node (private)
-
object
$copy -
Object where the new tree is copied to
Return value
returns True uns success
Throws
throws no exceptions thrown
Note
This function can not be called statically.
DB_NestedSet::createLeftNode
DB_NestedSet::createLeftNode() – Creates a node before a given node
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::createLeftNode
(
int
$id
,
array
$values
,
bool
$returnID
)
Description
+-- root1
|
+-\ root2
| |
| |-- subnode2 [new]
| |-- subnode1 [target]
| |-- subnode3
|
+-- root3
Parameter
-
integer
$id -
Target node ID
-
array
$values -
Hash with param => value pairs of the node (see $this->params)
-
boolean
$returnID -
Tell the method to return a node id instead of an object. ATTENTION: That the method defaults to return an object instead of the node id has been overseen and is basically a bug. We have to keep this to maintain BC. You will have to set $returnID to TRUE to make it behave like the other creation methods. This flaw will get fixed with the next major version.
Return value
returns The node id or false on error
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Create left node
Firstly, we connect to NestedSet using Factory. Then we create some nodes and finally we create a LeftNode. The LeftNode will be placed leftsided to the first root-node.
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$nestedSet->createSubNode($parent, array('name' => 'sub1'));
$nestedSet->createSubNode($parent, array('name' => 'sub2'));
$nestedSet->createLeftNode($parent, array('name' => 'left node'), true);
?>
DB_NestedSet::createRightNode
DB_NestedSet::createRightNode() – Creates a node after a given node
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::createRightNode
(
int
$id
,
array
$values
,
bool
$returnID
)
Description
+-- root1
|
+-\ root2
| |
| |-- subnode1 [target]
| |-- subnode2 [new]
| |-- subnode3
|
+-- root3
Parameter
-
integer
$id -
Target node ID
-
array
$values -
Hash with param => value pairs of the node (see $this->params)
-
boolean
$returnID -
Tell the method to return a node id instead of an object. ATTENTION: That the method defaults to return an object instead of the node id has been overseen and is basically a bug. We have to keep this to maintain BC. You will have to set $returnID to TRUE to make it behave like the other creation methods. This flaw will get fixed with the next major version.
Return value
returns The node id or false on error
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Create right node
Firstly, we connect to NestedSet using Factory. Then we create some nodes and finally we create a RightNode. The RightNode will be placed rightsided to the first root-node.
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$nestedSet->createSubNode($parent, array('name' => 'sub1'));
$nestedSet->createSubNode($parent, array('name' => 'sub2'));
$nestedSet->createRightNode($parent, array('name' => 'right node'), true);
?>
DB_NestedSet::createRootNode
DB_NestedSet::createRootNode() – Creates a new root node. If no id is specified then it is either added to the beginning/end of the tree based on the $pos.
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::createRootNode
(
array
$values
,
integer
$id
= false
,
bool
$first
= false
,
string
$pos = NESE_MOVE_AFTER
)
Description
Optionally it deletes the whole tree and creates one initial rootnode
+-- root1 [target]
|
+-- root2 [new]
|
+-- root3
Parameter
-
array
$values -
Hash with param => value pairs of the node (see $this->params)
-
integer
$id -
ID of target node (the rootnode after which the node should be inserted)
-
boolean
$first -
Danger: Deletes and (re)inits the whole tree - sequences are reset
-
string
$pos -
The position in which to insert the new node.
Return value
returns The node id or false on error
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Create rootnodes
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->createRootNode(array('name' => 'rootnode'), false, true);
?>
DB_NestedSet::createSubNode
DB_NestedSet::createSubNode() – Creates a subnode
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::createSubNode
(
integer
$id
,
array
$values
)
Description
+-- root1
|
+-\ root2 [target]
| |
| |-- subnode1 [new]
|
+-- root3
Parameter
-
integer
$id -
Parent node ID
-
array
$values -
Hash with param => value pairs of the node (see $this->params)
Return value
returns The node id or false on error
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Create subnodes
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'rootnode'), false, true);
$nestedSet->createSubNode($parent, array('name' => "node"));
?>
DB_NestedSet::deleteNode
DB_NestedSet::deleteNode() – Deletes a node
Synopsis
require_once 'DB/NestedSet.php';
bool
DB_NestedSet::deleteNode
(
int
$id
)
Description
This package is not documented yet.
Parameter
-
integer
$id -
ID of the node to be deleted
Return value
returns True if the delete succeeds
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Delete nodes
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$nestedSet->deleteNode($id);
?>
DB_NestedSet::factory
DB_NestedSet::factory() – Handles the returning of a concrete instance of DB_NestedSet based on the driver.
Synopsis
require_once 'DB/NestedSet.php';
object The&
DB_NestedSet::factory
(
string
$driver
,
string
$dsn
,
array
$params = array()
)
Description
If the class given by $driver allready exists it will be used. If not the driver will be searched inside the default path ./NestedSet/
Parameter
-
string
$driver -
The driver, such as DB or MDB
-
string
$dsn -
The dsn for connecting to the database
-
array
$params -
The field name params for the node table
Return value
returns DB_NestedSet object
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Factory
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
?>
DB_NestedSet::getAllNodes
DB_NestedSet::getAllNodes() – Fetch the whole NestedSet
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::getAllNodes
(
bool
$keepAsArray
= false
,
bool
$aliasFields
= true
,
array
$addSQL = array()
)
Description
This package is not documented yet.
Parameter
-
boolean
$keepAsArray -
(optional) Keep the result as an array or transform it into a set of DB_NestedSet_Node objects?
-
boolean
$aliasFields -
(optional) Should we alias the fields so they are the names of the parameter keys, or leave them as is?
-
array
$addSQL -
(optional) Array of additional params to pass to the query.
Return value
returns False on error, or an array of nodes
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Get all nodes
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$nestedSet->createSubNode($parent, array('name' => 'sub1');
$nestedSet->createSubNode($parent, array('name' => 'sub2');
$data = $nestedSet->getAllNodes(true);
?>
DB_NestedSet::getBranch
DB_NestedSet::getBranch() – Fetch the whole branch where a given node id is in
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::getBranch
(
int
$id
,
bool
$keepAsArray
= false
,
bool
$aliasFields
= true
,
array
$addSQL = array()
)
Description
This package is not documented yet.
Parameter
-
integer
$id -
The node ID
-
boolean
$keepAsArray -
(optional) Keep the result as an array or transform it into a set of DB_NestedSet_Node objects?
-
boolean
$aliasFields -
(optional) Should we alias the fields so they are the names of the parameter keys, or leave them as is?
-
array
$addSQL -
(optional) Array of additional params to pass to the query.
Return value
returns False on error, or an array of nodes
See
see _addSQL
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Get Branch
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$parent2 = $nestedSet->createSubNode($parent, array('name' => 'sub-node));
$nestedSet->createSubNode($parent2, array('name' => 'sub1'));
$nestedSet->createSubNode($parent2, array('name' => 'sub2'));
$data = getBranch($parent2);
?>
DB_NestedSet::getChildren
DB_NestedSet::getChildren() – Fetch the children _one level_ after of a node given by id
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::getChildren
(
int
$id
,
bool
$keepAsArray
= false
,
bool
$aliasFields
= true
,
bool
$forceNorder
= false
,
array
$addSQL = array()
)
Description
This package is not documented yet.
Parameter
-
integer
$id -
The node ID
-
boolean
$keepAsArray -
(optional) Keep the result as an array or transform it into a set of DB_NestedSet_Node objects?
-
boolean
$aliasFields -
(optional) Should we alias the fields so they are the names of the parameter keys, or leave them as is?
-
boolean
$forceNorder -
(optional) Force the result to be ordered by the norder param (as opposed to the value of secondary sort). Used by the move and add methods.
-
array
$addSQL -
(optional) Array of additional params to pass to the query.
Return value
returns False on error, or an array of nodes
See
see _addSQL
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Get Children
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$parent2 = $nestedSet->createSubNode($parent, array('name' => 'sub-node));
$nestedSet->createSubNode($parent2, array('name' => 'sub1'));
$nestedSet->createSubNode($parent2, array('name' => 'sub2'));
$data = $nestedSet->getChildren($parent2);
?>
DB_NestedSet::getParent
DB_NestedSet::getParent() – Fetch the immediate parent of a node given by id
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::getParent
(
int
$id
,
bool
$keepAsArray
= false
,
bool
$aliasFields
= true
,
array
$addSQL = array()
,
$useDB
= true
)
Description
This package is not documented yet.
Parameter
-
integer
$id -
The node ID
-
boolean
$keepAsArray -
(optional) Keep the result as an array or transform it into a set of DB_NestedSet_Node objects?
-
boolean
$aliasFields -
(optional) Should we alias the fields so they are the names of the parameter keys, or leave them as is?
-
array
$addSQL -
(optional) Array of additional params to pass to the query.
-
$useDB
Return value
returns False on error, or the parent node
See
see _addSQL
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Get Parent
Fetch the immediate parent of a node given by id. GetParent will return $parent2 as $data.
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$parent2 = $nestedSet->createSubNode($parent, array('name' => 'sub-node));
$nestedSet->createSubNode($parent2, array('name' => 'sub1'));
$nestedSet->createSubNode($parent2, array('name' => 'sub2'));
$data = $nestedSet->getParent($parent2);
?>
DB_NestedSet::getParents
DB_NestedSet::getParents() – Fetch the parents of a node given by id
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::getParents
(
int
$id
,
bool
$keepAsArray
= false
,
bool
$aliasFields
= true
,
array
$addSQL = array()
)
Description
This package is not documented yet.
Parameter
-
integer
$id -
The node ID
-
boolean
$keepAsArray -
(optional) Keep the result as an array or transform it into a set of DB_NestedSet_Node objects?
-
boolean
$aliasFields -
(optional) Should we alias the fields so they are the names of the parameter keys, or leave them as is?
-
array
$addSQL -
(optional) Array of additional params to pass to the query.
Return value
returns False on error, or an array of nodes
See
see _addSQL
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Get Parents
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$parent2 = $nestedSet->createSubNode($parent, array('name' => 'sub-node));
$parent3 = $nestedSet->createSubNode($parent2, array('name' => 'sub-node'));
$nestedSet->createSubNode($parent3, array('name' => 'sub1'));
$nestedSet->createSubNode($parent3, array('name' => 'sub2'));
$data = $nestedSet->getParents($parent3);
?>
DB_NestedSet::getRootNodes
DB_NestedSet::getRootNodes() – Fetches the first level (the rootnodes) of the NestedSet
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::getRootNodes
(
bool
$keepAsArray
= false
,
bool
$aliasFields
= true
,
array
$addSQL = array()
)
Description
This package is not documented yet.
Parameter
-
boolean
$keepAsArray -
(optional) Keep the result as an array or transform it into a set of DB_NestedSet_Node objects?
-
boolean
$aliasFields -
(optional) Should we alias the fields so they are the names of the parameter keys, or leave them as is?
-
array
$addSQL -
(optional) Array of additional params to pass to the query.
Return value
returns False on error, or an array of nodes
See
see _addSQL
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Get Rootnodes
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$nestedSet->createSubNode($parent, array('name' => 'sub1'));
$parent2 = $nestedSet->createRootNode($parent, array('name' => 'sub-node), '1', false);
$nestedSet->createSubNode($parent2, array('name' => 'sub2'));
$data = $nestedSet->getRootNodes();
?>
DB_NestedSet::getSiblings
DB_NestedSet::getSiblings() – Fetch all siblings of the node given by id Important: The node given by ID will also be returned Do a unset($array[$id]) on the result if you don't want that
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::getSiblings
(
int
$id
,
bool
$keepAsArray
= false
,
bool
$aliasFields
= true
,
array
$addSQL = array()
)
Description
This package is not documented yet.
Parameter
-
integer
$id -
The node ID
-
boolean
$keepAsArray -
(optional) Keep the result as an array or transform it into a set of DB_NestedSet_Node objects?
-
boolean
$aliasFields -
(optional) Should we alias the fields so they are the names of the parameter keys, or leave them as is?
-
array
$addSQL -
(optional) Array of additional params to pass to the query.
Return value
returns False on error, or the parent node
See
see _addSQL
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Get Siblings
<?php
require_once 'DB/NestedSet.php';
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$node = $nestedSet->createSubNode($parent, array('name' => 'sub1'));
$nestedSet->createSubNode($parent, array('name' => 'sub2'));
$nestedSet->createSubNode($parent, array('name' => 'sub3'));
$data = $nestedSet->getSiblings($node);
?>
DB_NestedSet::getSubBranch
DB_NestedSet::getSubBranch() – Fetch all the children of a node given by id
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::getSubBranch
(
string
$id
,
bool
$keepAsArray
= false
,
bool
$aliasFields
= true
,
array
$addSQL = array()
)
Description
getChildren only queries the immediate children getSubBranch returns all nodes below the given node
Parameter
-
string
$id -
The node ID
-
boolean
$keepAsArray -
(optional) Keep the result as an array or transform it into a set of DB_NestedSet_Node objects?
-
boolean
$aliasFields -
(optional) Should we alias the fields so they are the names of the parameter keys, or leave them as is?
-
array
$addSQL -
(optional) Array of additional params to pass to the query.
Return value
returns False on error, or an array of nodes
See
see _addSQL
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Get SubBranch
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$parent2 = $nestedSet->createSubNode($parent, array('name' => 'sub-node));
$parent3 = $nestedSet->createSubNode($parent2, array('name' => 'sub-node));
$nestedSet->createSubNode($parent3, array('name' => 'sub1'));
$nestedSet->createSubNode($parent3, array('name' => 'sub2'));
$data = $nestedSet->getSubBranch($parent2);
?>
DB_NestedSet::isParent
DB_NestedSet::isParent() – See if a given node is a parent of another given node
Synopsis
require_once 'DB/NestedSet.php';
bool
DB_NestedSet::isParent
(
mixed
$parent
,
mixed
$child
)
Description
A node is considered to be a parent if it resides above the child So it doesn't mean that the node has to be an immediate parent. To get this information simply compare the levels of the two nodes after you know that you have a parent relation.
Parameter
-
mixed
$parent -
The parent node as array or object
-
mixed
$child -
The child node as array or object
Return value
returns True if it's a parent
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
IsParent
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'));
$node = $nestedSet->createSubNode($parent, array('name' => 'sub1'));
$boolparent = $nestedSet->isParent($parent, $node);
?>
DB_NestedSet::moveTree
DB_NestedSet::moveTree() – Wrapper for node moving and copying
Synopsis
require_once 'DB/NestedSet.php';
int
DB_NestedSet::moveTree
(
int
$id
,
$targetid
,
constant
$pos
,
bool
$copy
= false
,
int
$target
)
Description
This package is not documented yet.
Parameter
-
integer
$id -
Source ID
-
$targetid -
Target ID
-
constant
$pos -
Position (use one of the NESE_MOVE_* constants)
-
boolean
$copy -
Shall we create a copy
-
integer
$target -
Target ID
Return value
returns ID of the moved node or false on error
See
see _moveInsideLevel
see _moveRoot2Root
see _moveAcross
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Get SubBranch
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$parent2 = $nestedSet->createSubNode($parent, array('name' => 'sub-node));
$parent3 = $nestedSet->createSubNode($parent2, array('name' => 'sub-node));
$nestedSet->createSubNode($parent3, array('name' => 'sub1'));
$node = $nestedSet->createSubNode($parent3, array('name' => 'sub2'));
$nestedSet->moveTree($node, $parent, NESE_MOVE_AFTER);
?>
DB_NestedSet::pickNode
DB_NestedSet::pickNode() – Fetch the data of a node with the given id
Synopsis
require_once 'DB/NestedSet.php';
mixed
DB_NestedSet::pickNode
(
int
$id
,
bool
$keepAsArray
= false
,
bool
$aliasFields
= true
,
string
$idfield = 'id'
,
array
$addSQL = array()
)
Description
This package is not documented yet.
Parameter
-
integer
$id -
The node id of the node to fetch
-
boolean
$keepAsArray -
(optional) Keep the result as an array or transform it into a set of DB_NestedSet_Node objects?
-
boolean
$aliasFields -
(optional) Should we alias the fields so they are the names of the parameter keys, or leave them as is?
-
string
$idfield -
(optional) Which field has to be compared with $id? This is can be used to pick a node by other values (e.g. its name).
-
array
$addSQL -
(optional) Array of additional params to pass to the query.
Return value
returns False on error, or an array of nodes
See
see _addSQL
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Pick Node
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$parent = $nestedSet->createRootNode(array('name' => 'root-node'), false, true);
$nestedSet->createSubNode($parent, array('name' => 'sub1'));
$data = $nestedSet->getBranch($id);
?>
DB_NestedSet::removeListener
DB_NestedSet::removeListener() – Removes an event listener
Synopsis
require_once 'DB/NestedSet.php';
bool
DB_NestedSet::removeListener
(
string
$event
,
string
$listenerID
)
Description
Removes the event listener with the given ID
Parameter
-
string
$event -
The ivent name
-
string
$listenerID -
The listener's ID
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Remove Listener
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->AddListener("nodeCreate", "listener");
$nestedSet->RemoveListener("nodeCreate", "listener");
?>
DB_NestedSet::setAttr
DB_NestedSet::setAttr() – Sets an object attribute
Synopsis
require_once 'DB/NestedSet.php';
bool
DB_NestedSet::setAttr
(
array
$attr
)
Description
This package is not documented yet.
Parameter
-
array
$attr -
An associative array with attributes
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Set attributes
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->setAttr(array(
'node_table' => 'nested_set',
'lock_table' => 'nested_set_locks',
'secondarySort' => 'name'
)
);
?>
DB_NestedSet::setDbOption
DB_NestedSet::setDbOption() – Sets a db option. Example, setting the sequence table format
Synopsis
require_once 'DB/NestedSet.php';
void
DB_NestedSet::setDbOption
(
$option
,
$val
)
Description
This package is not documented yet.
Parameter
-
$option
-
$val
Throws
throws no exceptions thrown
Note
This function can not be called statically.
DB_NestedSet::setsortMode
DB_NestedSet::setsortMode() – This enables you to set specific options for each output method
Synopsis
require_once 'DB/NestedSet.php';
Current
DB_NestedSet::setsortMode
(
constant
$sortMode
= false
)
Description
This package is not documented yet.
Parameter
-
constant
$sortMode
Return value
returns sortMode
Throws
throws no exceptions thrown
Note
This function can not be called statically.
DB_NestedSet::testLock
DB_NestedSet::testLock() – Tests if a database lock is set
Synopsis
require_once 'DB/NestedSet.php';
void
DB_NestedSet::testLock
(
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Test lock
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->testLock();
?>
DB_NestedSet::triggerEvent
DB_NestedSet::triggerEvent() – Triggers and event an calls the event listeners
Synopsis
require_once 'DB/NestedSet.php';
bool
DB_NestedSet::triggerEvent
(
string
$event
,
&$node
,
array
$eparams
= false
,
object
$
)
Description
This package is not documented yet.
Parameter
-
string
$event -
The Event that occured
-
&$node -
Node
-
array
$eparams -
A associative array of params which may be needed by the handler
-
object
$node -
A Reference to the node object which was subject to changes
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Trigger Event
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->AddListener("nodeCreate", "listener");
$parent = $nestedSet->createRootNode(array('name' => 'rootnode'), false, true);
$node = $nestedSet->createSubNode($parent, array('name' => "node"));
$nestedSet->TriggerEvent("nodeDelete", $node);
?>
DB_NestedSet::updateNode
DB_NestedSet::updateNode() – Changes the payload of a node
Synopsis
require_once 'DB/NestedSet.php';
bool
DB_NestedSet::updateNode
(
int
$id
,
array
$values
,
$_internal
= false
,
bool
$_intermal
)
Description
This package is not documented yet.
Parameter
-
integer
$id -
Node ID
-
array
$values -
Hash with param => value pairs of the node (see $this->params)
-
$_internal -
Internal use only.
-
boolean
$_intermal -
Internal use only. Used to skip value validation. Leave this as it is.
Return value
returns True if the update is successful
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Example
Update nodes
<?php
require_once('DB/NestedSet.php');
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->createSubNode($id, array('name' => "rootnode"));
$nestedSet->updateNode($id, array('name' => "new name"));
?>