public __construct ($file)
Constructor method. Decodes the tree from the specified file in JSON format.
public path ($id, $titles = false, $tree = false)
Find the path to a specific node in the tree, including the node itself.
If titles is true, it will return an associative array with the keys being
object IDs and the values being their data attribute (usually, the title or
name). If $titles
is false, it will return an array of IDs only.
public add ($obj, $parent = false, $data = false)
Add an object to the tree under the specified parent node.
$id
can be an ID or a node object. If $data
is passed, it
it will set the data
property to that instead of the value
of $obj
, which would typically be used as follows:
$mytree->add ('id-value', 'parent-id', 'Title here');
public remove ($id, $recursive = true)
Remove an object from the tree. Removes all children as well unless you set $recursive to false.
public remove_path ($path)
Remove a specific path from the tree recursively. Used primarily by move().
Handles managing a tree of objects as a JSON file. Items in the tree have the following structure:
Item that have children will have an additional
children
property that is an array of other items.Usage: