Jet\Data_Tree_Node

Represents a tree node. The principle is described in the previous chapter

Overview of methods

Method Význam
public __construct(
Data_Tree $tree,
mixed $data
)
If it is not absolutely necessary, do not create the instance of the node directly, but always through the appropriate methods of the Jet\Data_Tree class .
public getTree(
) : Data_Tree
Returns an instance of the tree to which the node belongs.
public getIsRoot(
) : bool
Indicates whether this is a root node.
public getIsOrphan(
) : bool
Indicates whether it is a descendant.
public getId(
) : string
Returns the node identifier.
public setId(
string $id
)
Sets the node identifier. The method should only be used for the root node.
public getLabel(
) : string
Returns the label of the node.
public setLabel(
string $label
) : void
Sets the label of the node. Can be applied at any time to any node.
public getParentId(
) : string
Returns the identifier of the parent node.
public getRealParentId(
) : string
If it is an orphan, then it returns the real identifier of the parent node as it was in the input data and which actually differs from the current (adoptive) parent node.
public getParent(
) : Data_Tree_Node|null
Returns the parent node.
public getDepth(
) : int
Returns the embedding depth of the node.
public getData(
) : mixed
Returns the node data. De facto, it is the data from which the node was initially created. This means the associated field, or object. The data may contain additional information - not only that needed to build the tree.
public setData(
mixed $data
)
Sets the node data. However, it no longer affects the assembled storm.
public getHasChildren(
) : bool
Indicates whether the node has children.
public getChildren(
) : Data_Tree_Node[]
Returns direct descendants of a node (not descendants of descendants - only those from the next level).
public getAllChildrenIds(
) : array
Returns the identifiers of all children of a node. This also means descendants of descendants - to all levels.
public getChildExists(
string $id
) : bool
Indicates whether the node has a direct descendant (at the next following level) with the given identifier.
public getChild(
string $child_id
) : Data_Tree_Node
Returns the direct descendant with the given identifier.
public getPathToRoot(
) : Data_Tree_Node[]
Returns an array of the list of all parents from the root to the given node (inclusive), sorted chronologically from the node to the root.
public getPathFromRoot(
) : Data_Tree_Node[]
Returns an array of the list of all parents from the root to the given node (inclusive), sorted chronologically from the root to the node.
public getPath(
) : Data_Tree_Node[]
Alias method getPathFromRoot.
public toJSON(
) : string
It exports the tree to JSON in the same way as Data_Tree does, but only from the given node onwards - i.e. the given branch.
public jsonSerialize(
) : array
Exports the tree to JSON, or rather uses the json_encode function, similarly to what Data_Tree does, but only from the given node onwards - i.e. the given branch.
public toArray(
) : array
It exports the tree to the field in the same way as Data_Tree does, but only from the given node onwards - i.e. the given branch.
public setMaxDepth(
int|null $max_depth
) : void
Allows you to limit the depth to which the given branch will be exported or traversed by the iterator.

A value of null means no depth limit (which is the default).
public __sleep(
) : array
Prepares the tree for serialization.
public toString(
) : string

public __toString(
) : string
A node can be converted to a string. In fact, the label of the node is returned.
public current(
) : Data_Tree_Node
See PHP Iterator

Just as the whole tree can be traversed using foreach, so can a node and its children - i.e. a part/branch of the tree.
public key(
) : string
public next(
) : void
public valid(
) : bool
public rewind(
) : void
public count(
) : int
See PHP Countable
public getSelectOptionCssStyle(
) : string
The tree can be directly used for rendering form (or other UI) elements. Individual nodes can be styled for this purpose. For example, provide indentation according to plunge, color and so on.

See form field selection options
public setSelectOptionCssStyle(
string $css_style
) : void
public getSelectOptionCssClass(
) : string
public setSelectOptionCssClass(
string $css_class
) : void
Previous chapter
Working with a tree structure - Jet\Data_Tree
Next chapter
Jet\Data_Tree_Exception