Documentation

Treenode
in package
implements ArrayAccess

Represents a node in the tree

Table of Contents

Interfaces

ArrayAccess

Properties

$children  : array<string|int, static>
$parent  : static|null
$data  : mixed
$filtered_children  : mixed
$real_children  : mixed

Methods

__construct()  : mixed
Creates a node, with the specified data
__get()  : mixed
Generic field getter for unknown properties - used for TreeNode->children
__set()  : mixed
Generic field getter for unknown properties - used for TreeNode->children
filterChildren()  : mixed
Filter the children of this node, removing any children which don't match the specified TreenodeMatcher.
findAllNodes()  : array<string|int, static>
Finds all nodes which match the specified matcher.
findAncestors()  : array<string|int, static>
Finds all ancestors of a specific node, including the node, not including the root node of the tree The array is in order from top to bottom, so $ancestors[0] is the top-parent, and $ancestors[len-1] is the node.
findNode()  : static|null
Finds a node by looking at this node If that does not match, looking at each of this nodes children in turn.
findNodeValue()  : Treenode|null
Finds a node by looking at this node If that does not match, looking at each of this nodes children in turn.
getAllChildren()  : mixed
Returns an array of all children nodes, including sub-children
getChildren()  : array<string|int, static>
isOrphan()  : bool
Is this node an orphan? Orphans are at the top of the tree, and they don't have any children.
isRoot()  : mixed
Returns true if this node is the root node
loadTree()  : Treenode
Loads a flat table into a tree structure.
offsetExists()  : mixed
ArrayAccess function for checking if a specified key exists
offsetGet()  : mixed
ArrayAccess function for getting a value by its key
offsetSet()  : mixed
ArrayAccess function for setting a value by its key
offsetUnset()  : mixed
ArrayAccess function for unsetting a value
removeFilter()  : mixed
Removes the currently active filter

Properties

$children

public array<string|int, static> $children

$parent

public static|null $parent = null

$filtered_children

private mixed $filtered_children = null

$real_children

private mixed $real_children = array()

Methods

__construct()

Creates a node, with the specified data

public __construct([array<string|int, mixed> $data = null ]) : mixed
Parameters
$data : array<string|int, mixed> = null

Initial data for the node

__get()

Generic field getter for unknown properties - used for TreeNode->children

public & __get(string $field) : mixed

Be aware that data gotten through this getter is BY REFERENCE For by-value data retrival, use the array-access functions.

Parameters
$field : string

The field to get.

__set()

Generic field getter for unknown properties - used for TreeNode->children

public __set(string $field, mixed $value) : mixed
Parameters
$field : string

The field to set.

$value : mixed

The value to set.

filterChildren()

Filter the children of this node, removing any children which don't match the specified TreenodeMatcher.

public filterChildren(TreenodeMatcher $matcher) : mixed

The nodes are not actually removed, matching nodes are just added to a filtered children list Which is returned instead of the original children list.

Parameters
$matcher : TreenodeMatcher

findAllNodes()

Finds all nodes which match the specified matcher.

public findAllNodes(TreenodeMatcher $matcher) : array<string|int, static>
Parameters
$matcher : TreenodeMatcher

The matcher to use for finding the nodes.

Return values
array<string|int, static> —

The found nodes, or an empty array if no nodes were found.

findAncestors()

Finds all ancestors of a specific node, including the node, not including the root node of the tree The array is in order from top to bottom, so $ancestors[0] is the top-parent, and $ancestors[len-1] is the node.

public findAncestors() : array<string|int, static>

A B C D E F G H I

NODE RESULT ARRAY H B D H D B D B B A (empty)

Return values
array<string|int, static> —

The ancestors, as described above.

findNode()

Finds a node by looking at this node If that does not match, looking at each of this nodes children in turn.

public findNode(TreenodeMatcher $matcher) : static|null

If that does not match, return null

Parameters
$matcher : TreenodeMatcher

The matcher to use for finding the node.

Return values
static|null —

if found, null if not found.

findNodeValue()

Finds a node by looking at this node If that does not match, looking at each of this nodes children in turn.

public findNodeValue(mixed $key, mixed $value) : Treenode|null

If that does not match, return null

Parameters
$key : mixed

The key to search for in the data

$value : mixed

The value to search for in the data

Return values
Treenode|null —

if found, null if not found.

getAllChildren()

Returns an array of all children nodes, including sub-children

public getAllChildren([mixed $exclude_id = null ][, mixed $indent_str = ' ' ][, mixed $indent = 0 ]) : mixed

The array will be id => name. This function requires the table to have a column named 'name'. The name field will be indented according to the depth. If specified, the exclude_id argument will be used to exclude nodes (and their children) according to id.

Parameters
$exclude_id : mixed = null
$indent_str : mixed = ' '
$indent : mixed = 0

getChildren()

public & getChildren() : array<string|int, static>
Return values
array<string|int, static>

isOrphan()

Is this node an orphan? Orphans are at the top of the tree, and they don't have any children.

public isOrphan() : bool
Return values
bool —

if it's an orphan, false otherwise

isRoot()

Returns true if this node is the root node

public isRoot() : mixed

loadTree()

Loads a flat table into a tree structure.

public static loadTree(string $table[, array<string|int, mixed> $conditions = ['1'] ][, string $order = 'record_order' ]) : Treenode

Requires the table to have an id, parent_id and record_order field.

Parameters
$table : string

The name of the table to load

$conditions : array<string|int, mixed> = ['1']

Query conditions, in the format used by Pdb::buildClause

$order : string = 'record_order'

The column to order by. Defaults to 'record_order'

Return values
Treenode —

The loaded tree

offsetExists()

ArrayAccess function for checking if a specified key exists

public offsetExists(mixed $offset) : mixed
Parameters
$offset : mixed

The offset to check.

Attributes
#[ReturnTypeWillChange]

offsetGet()

ArrayAccess function for getting a value by its key

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed

The offset to get.

Attributes
#[ReturnTypeWillChange]

offsetSet()

ArrayAccess function for setting a value by its key

public offsetSet(mixed $offset, mixed $value) : mixed
Parameters
$offset : mixed

The offset to set.

$value : mixed

The value to set.

Attributes
#[ReturnTypeWillChange]

offsetUnset()

ArrayAccess function for unsetting a value

public offsetUnset(mixed $offset) : mixed
Parameters
$offset : mixed

The offset to remove.

Attributes
#[ReturnTypeWillChange]

removeFilter()

Removes the currently active filter

public removeFilter() : mixed
On this page

Search results