The constructor does some initializations.
Tree
Tree
()
Adds the specified node to the tree and makes it a child of the specified parent. If the parent is not specified, then it makes the node a root. Always use this method instead of the addChild() method of the individual tree nodes.
void
addNode
(ref $node, optional $parent, [optional $clearTraversal = false])
-
ref
$node: object The node to add.
-
optional
$parent: ref object parent The node that will become the parent of the added node.
-
optional
$clearTraversal: boolean $clearTraversal If true, the tree will clear its traversal cache. This is needed when changing parentage.
Redefinition of:
- TreeInterface::addNode()
- Adds the specified node to the hierarchy and makes it a child of the specified parent. If the parent is not specified, then it makes the node a root.
Clear the traverse caches for the given node and direction
void
clearTraversalCaches
(object Node $node, boolean $down)
-
object Node
$node
-
boolean
$down
Clear the traverse down caches for the given node and all of its ancestors
void
clearTraverseDownCaches
(object Node $node)
Clear the traverse up caches for the given node and all of its decendents
void
clearTraverseUpCaches
(object Node $node)
Delete the node from the tree. This can only be done if the node has no parents and no children.
void
deleteNode
(object node $node, [mixed $clearTraversal = false])
-
object node
$node: The node to delete.
Redefinition of:
- TreeInterface::deleteNode()
- Delete the node from the tree. This can only be done if the node has no parents and no children.
Answer the traversal cacheKey for this node, direction, and levels
string
getCacheKey
(object Node $node, boolean $down, integer $levels)
-
object Node
$node
-
boolean
$down
-
integer
$levels
Returns the node with the specified id. If it does not exist, return
- null
.
ref
getNode
(mixed $id)
-
mixed
$id: id The id of the requested node.
Redefinition of:
- TreeInterface::getNode()
- Returns the node with the specified id. If it does not exist, return
- null
.
Simply returns all nodes of this tree in an array in no particular order.
ref
getNodes
()
Returns the size (number of nodes) in this tree.
integer
getSize
()
Redefinition of:
- TreeInterface::getSize()
- Returns the size (number of nodes) in this hierarchy.
Returns
- true
if the node with the specified id (string) exists.
boolean
nodeExists
(mixed $id)
-
mixed
$id: id The id of the node.
Redefinition of:
- TreeInterface::nodeExists()
- Returns
- true
if the node with the specified id (string) exists.
Traverses the tree and returns all the nodes in an array. The traversal is a depth-first pre-order traversal starting from the specified node.
ref
traverse
(ref $node, boolean $down, integer $levels)
-
ref
$node: object node The node to start traversal from.
-
boolean
$down: down If
- true
, this argument specifies that the traversal will go down the children; if - false
then it will go up the parents.
-
integer
$levels: levels Specifies how many levels of nodes remain to be fetched. This will be recursively decremented and at 0 the recursion will stop. If this is negative then the recursion will go on until the last level is processed.
Redefinition of:
- TreeInterface::traverse()
- Traverses the hierarchy and returns all the nodes in an array. The traversal is a pre-order traversal starting from the specified node.
A private recursive function that performs a depth-first pre-order traversal.
ref
_traverse
(ref &$result, ref $node, boolean $down, integer $levels, integer $startingLevel, [string $initiatingNodeId = null])
-
string
$initiatingNodeId: The node that initiated the traversal to this node
-
ref
&$result: array The array where to store the result. Will consists of all nodes in the tree visited in a pre-order manner.
-
ref
$node: object node The node to be visited.
-
boolean
$down: down If
- true
, this argument specifies that the traversal will go down the children; if - false
then it will go up the parents.
-
integer
$levels: levels Specifies how many levels of nodes remain to be fetched. This will be recursively decremented and at 0 the recursion will stop. If this is negative then the recursion will go on until the last level is processed.
-
integer
$startingLevel: startingLevels This is the original value of the levels. This is needed in order to properly calculate the relative depth of each returned node.
Inherited Methods
Inherited From TreeInterface
TreeInterface::addNode()
TreeInterface::deleteNode()
TreeInterface::getAllNodes()
TreeInterface::getAncestors()
TreeInterface::getNode()
TreeInterface::getSize()
TreeInterface::getSubtree()
TreeInterface::nodeExists()
TreeInterface::traverse()