Horde_Tree
in package
implements
Countable
The Horde_Tree class provides a tree view of hierarchical information. It allows for expanding/collapsing of branches.
Copyright 2003-2017 Horde LLC (http://www.horde.org/)
See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Tags
Interfaces, Classes, Traits and Enums
- Countable
Table of Contents
- TOGGLE = 'ht_toggle_'
- The preceding text, before the Horde_Tree instance name, used for collapse/expand submissions.
- $instance : string
- The name of this instance.
- $_nodes : array<string|int, mixed>
- An array containing all the tree nodes.
- $_root_nodes : array<string|int, mixed>
- The top-level nodes in the tree.
- $_session : array<string|int, mixed>
- Callbacks used to store session data.
- $_sortCriteria : mixed
- __construct() : mixed
- Constructor.
- addNode() : mixed
- Adds a node to the node tree array.
- addNodeParams() : mixed
- Adds additional parameters to a node.
- count() : int
- getNodes() : array<string|int, mixed>
- Returns the nodes of the tree.
- getRootNodes() : array<string|int, mixed>
- Returns the root node IDs.
- isExpanded() : bool
- Returns whether the specified node is currently expanded.
- nodeId() : string
- Returns the escaped node ID.
- sort() : mixed
- Sorts the tree by the specified node property.
- sortHelper() : mixed
- Helper method for sort() to compare two tree elements.
- _buildIndents() : mixed
- Set the indent level for each node in the tree.
Constants
TOGGLE
The preceding text, before the Horde_Tree instance name, used for collapse/expand submissions.
public
mixed
TOGGLE
= 'ht_toggle_'
Properties
$instance
The name of this instance.
public
string
$instance
$_nodes
An array containing all the tree nodes.
protected
array<string|int, mixed>
$_nodes
= array()
$_root_nodes
The top-level nodes in the tree.
protected
array<string|int, mixed>
$_root_nodes
= array()
$_session
Callbacks used to store session data.
protected
array<string|int, mixed>
$_session
= array()
$_sortCriteria
protected
mixed
$_sortCriteria
Methods
__construct()
Constructor.
public
__construct(string $name[, array<string|int, mixed> $session = array() ]) : mixed
Parameters
- $name : string
-
The name of this tree instance.
- $session : array<string|int, mixed> = array()
-
Callbacks used to store session data. Must define two keys: 'get' and 'set'. Function definitions: (string) = get([string - Instance], [string - ID]); set([string - Instance], [string - ID], [boolean - value]); DEFAULT: No session storage
Return values
mixed —addNode()
Adds a node to the node tree array.
public
addNode(array<string|int, mixed> $node) : mixed
Parameters
- $node : array<string|int, mixed>
-
A hash with node properties:
- id: (string) The unique node id.
- parent: (string) The parent's unique node id.
- label: (string) The text label for the node.
- expanded: (boolean) Is this level expanded or not.
- params: (array) Any other parameters to set (see addNodeParams() of the renderers for full details).
Return values
mixed —addNodeParams()
Adds additional parameters to a node.
public
addNodeParams(string $id[, array<string|int, mixed> $params = array() ]) : mixed
Parameters
- $id : string
-
The unique node id.
- $params : array<string|int, mixed> = array()
-
Parameters to set (key/value pairs).
Return values
mixed —count()
public
count() : int
Return values
int —getNodes()
Returns the nodes of the tree.
public
getNodes() : array<string|int, mixed>
Return values
array<string|int, mixed> —The nodes with IDs as keys and node hashes as values.
getRootNodes()
Returns the root node IDs.
public
getRootNodes() : array<string|int, mixed>
Return values
array<string|int, mixed> —The root nodes.
isExpanded()
Returns whether the specified node is currently expanded.
public
isExpanded(mixed $id) : bool
Parameters
- $id : mixed
-
The unique node id.
Return values
bool —True if the specified node is expanded.
nodeId()
Returns the escaped node ID.
public
nodeId(string $id) : string
Parameters
- $id : string
-
Node ID.
Return values
string —Escaped node ID.
sort()
Sorts the tree by the specified node property.
public
sort(string $criteria[, int $id = -1 ]) : mixed
Parameters
- $criteria : string
-
The node property to sort by.
- $id : int = -1
-
Used internally for recursion.
Return values
mixed —sortHelper()
Helper method for sort() to compare two tree elements.
public
sortHelper(mixed $a, mixed $b) : mixed
Parameters
- $a : mixed
- $b : mixed
Return values
mixed —_buildIndents()
Set the indent level for each node in the tree.
protected
_buildIndents(array<string|int, mixed> $nodes, int $indent) : mixed
Parameters
- $nodes : array<string|int, mixed>
-
TODO
- $indent : int
-
TODO