Class TreeItem Class to create tree-based items

The treeitem class allows you to logically store tree-based structures.

Example:

Let's have a tree with 3 nodes. It's important that we always have a "root" key.

$root = new TreeItem("root", 1); $item1 = new TreeItem("node1",2); $item2 = new TreeItem("node2",3); $item3 = new TreeItem("node3",4);

$root->addItem($item1); $root->addItem($item2); $root->addItem($item3);

This represents the tree we described above.

If you know the ID of the item you want to add to, there's no need to have a specific item handy, but rather you can use the "addItemToID" function.

 Methods

Constructor Function Creates a new, independant tree item.

TreeItem(string $name, string $id, boolean $collapsed) 

Parameters

$name

string

The name of that item

$id

string

The unique ID of that item

$collapsed

boolean

Is this item collapsed by default

addItem Adds a new subitem to this item.

addItem(object $item) 

Parameters

$item

object

the item to add

addItemToID Adds a new subitem to a specific item with an ID.

addItemToID(object $item, string $id) 

Traverses all subitems to find the correct item.

Parameters

$item

object

the item to add

$id

string

the ID to add the item to

collapseAll Collapses all items, starting from the $start item.

collapseAll(string $start) 

Parameters

$start

string

the ID to start collapsing from

expandAll Expands all items, starting from the $start item.

expandAll(string $start) 

Parameters

$start

string

the ID to start expanding from

getCollapsedList Returns all items (as ID array) which are collapsed.

getCollapsedList(array $list) 

Parameters

$list

array

Contains the list with all collapsed items

getExpandedList Returns all items (as ID array) which are expanded.

getExpandedList(array $list) 

Parameters

$list

array

Contains the list with all expanded items

Starts iterating at root node and flattens the tree into an array

getFlatTree($item, $flat_tree) 

Parameters

$item

$flat_tree

getItemByID Retrieves a specific item by its ID. Note that this function traverses all subitems to find the correct item.

getItemByID(string $id) : object

Parameters

$id

string

the ID to find

Returns

objectThe item, or false if nothing was found

Returns a list of the id of all parent nodes of the given node Not using the nodes of hierarchical tree, but flat tree !!

getParentNodes($parentNodes, $stop_id) 

Parameters

$parentNodes

$stop_id

getCollapsedList thinks if a node has no subnodes it is collapsed I don't think so

getRealCollapsedList($list) 

Parameters

$list

Returns a list of the id of all parent nodes of the given node

getTreeParentNodes($parentNodes, $id) 

Parameters

$parentNodes

$id

hasCollapsedNode()

hasCollapsedNode($item_id) 

Parameters

$item_id

isCustomAttributeSet checks if a specific custom attribute is set

isCustomAttributeSet(string $item) 

Parameters

$item

string

the attribute name to find

markCollapsed Marks an item as collpased. Traverses all subitems to find the ID. Note that only the item with $id is collapsed, but not its childs.

markCollapsed(string $id) 

Parameters

$id

string

the ID to collapse

markExpanded Marks an item as expanded. Traverses all subitems to find the ID. Note that only the item with $id is expanded, but not its childs.

markExpanded(string $id) 

Parameters

$id

string

the ID to expand, or an array with all id's

removeItem Removes an item with a specific ID.

removeItem(string $id) 

Parameters

$id

string

the ID to find

traverse traverses the tree starting from this item, and returning all objects as $objects.

traverse(object $objects, integer $level) 

Parameters

$objects

object

all found objects

$level

integer

Level to start on

 Properties

 

Determinates if this tree item is collapsed

$collapsed : boolean

 

Icon for the collapsed item

$collapsed_icon : string

 

Contains custom entries

$custom : array

 

Icon for the expanded item

$expanded_icon : string

 

ID for this item

$id : string

 

Icon for last node in a branch

$lastnode_icon : string

 

Contains the level of this item

$level : integer

 

Name for this item

$name : string

 

Contains the parent of this item

$parent : array

 

Sub Items for this tree item

$subitems : array