pclib
3.0.0
Lightweight PHP framework
|
Display tree structure. More...
Public Member Functions | |
__construct ($path='') | |
Create Tree instance. More... | |
importText ($s) | |
Import Tree from text string. More... | |
exportText () | |
Export current Tree to text string. More... | |
fromArray ($nodes) | |
Import Tree from array of $nodes. More... | |
toArray () | |
Export Tree as array of $nodes. More... | |
get ($nodeId) | |
Get Tree node. More... | |
set ($nodeId, $data) | |
Set Tree node values. More... | |
find ($key, $value) | |
Find Tree node by node parameter. More... | |
map (callable $fn) | |
Call $fn for each node. More... | |
fromQuery ($sql, $topId=0) | |
Load tree from database query. More... | |
load ($treeId, $topId=0, $maxLevel=0) | |
Load tree from table tree_lookups. More... | |
save ($treeId) | |
Save current tree to table tree_lookups. More... | |
expand () | |
Expand path(s) in current tree. More... | |
expandLevel ($level) | |
Expand tree to level $level. | |
html () | |
Return html output of the current tree. | |
Public Member Functions inherited from BaseObject | |
loadDefaults ($className=null) | |
Load default parameters of class $className into object instance. | |
setProperties (array $defaults) | |
Set public properties of object from the array. More... | |
Data Fields | |
$db | |
var Db Link to database object. | |
$table = 'TREE_LOOKUPS' | |
Database table for storing tree data. | |
$tpl | |
var Tpl Tree template. | |
$auth = null | |
If set, it will check user rights against RKEY column. | |
Data Fields inherited from BaseObject | |
$serviceLocator | |
var function() Return service object when requested with service(). | |
Protected Member Functions | |
addNode ($data) | |
Called everytime when adding node to the tree. | |
expandPath ($nodeKey) | |
Expand (open) current tree to node $nodeKey. More... | |
Protected Member Functions inherited from BaseObject | |
service ($service, $default=null) | |
Try acquire $service and load it into property $this->$service. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from BaseObject | |
static | defaults () |
Set or retireve default parameters of the object. More... | |
Display tree structure.
Default template will show tree as unordered list (UL). Features:
__construct | ( | $path = '' | ) |
Create Tree instance.
string | $path | Filename of template file. By default it uses default-tree.tpl. |
expand | ( | ) |
Expand path(s) in current tree.
int|array | Id of nodes, which should be expanded (opened) Ex: $tree->expand(1,4,20) Expand tree to nodes 1,4,20 |
|
protected |
Expand (open) current tree to node $nodeKey.
int | $nodeKey | Key in Tree::nodes array |
exportText | ( | ) |
Export current Tree to text string.
find | ( | $key, | |
$value | |||
) |
Find Tree node by node parameter.
string | $key | Node key |
string | $value | Value of node key |
fromArray | ( | $nodes | ) |
Import Tree from array of $nodes.
array | $nodes | [['ID'=>'','LABEL'=>'','LEVEL'=>'',...],...] |
fromQuery | ( | $sql, | |
$topId = 0 |
|||
) |
Load tree from database query.
Expected fields: ID, LABEL, PARENT_ID.
string | $sql | Database query |
int | $topId |
get | ( | $nodeId | ) |
Get Tree node.
int | $nodeId |
importText | ( | $s | ) |
Import Tree from text string.
string | $s | Source string. See https://pclib.brambor.net/demo/?r=source/tree.txt |
load | ( | $treeId, | |
$topId = 0 , |
|||
$maxLevel = 0 |
|||
) |
Load tree from table tree_lookups.
int | $treeId |
map | ( | callable | $fn | ) |
Call $fn for each node.
callable | $fn,(array | $node) : array Callback function. It takes Tree $node and must return this $node. |
save | ( | $treeId | ) |
Save current tree to table tree_lookups.
int | $treeId |
set | ( | $nodeId, | |
$data | |||
) |
Set Tree node values.
int | $nodeId | |
array | $data | Data of node to be set. |
toArray | ( | ) |