pclib  2.3.2
Lightweight PHP framework
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Tree Class Reference

Load tree structure and render it as unordered list (ul). More...

Inheritance diagram for Tree:
BaseObject

Public Member Functions

 __construct ($cssClass= 'pctree')
 Create Tree instance. More...
 
 html ()
 Return HTML of current tree. More...
 
 out ()
 Print current tree. More...
 
 load ($fileName)
 Load tree from the text file. More...
 
 setString ($str)
 Load tree from the text string. More...
 
 getTree ($tree_id, $node_id=null, $maxlevel=null)
 Load tree $tree_id from table Tree::table. More...
 
 getSubTree ($node_id, $maxlevel=null)
 Load subtree of node $node_id from table Tree::table. More...
 
 addTree ($tree_id, $node_id=null)
 Add current tree to the database table. More...
 
 addSubTree ($node_id)
 Add current tree as subtree of $node_id. More...
 
 addNode ($node_id, array $node)
 Insert node $node after $node_id. More...
 
 addNodeBefore ($node_id, array $node)
 Insert node $node before $node_id. More...
 
 addChild ($node_id, array $node)
 Insert node $node as child of $node_id. More...
 
 getChildren ($node_id)
 Return children of node_id as flat array. More...
 
 addChildren ($node_id, array $nodes)
 Add children to node_id. More...
 
 rmChildren ($node_id)
 Remove children of node_id from database table. More...
 
 rmNode ($node_id)
 Remove node from database table. More...
 
 expand ()
 Expand path(s) in current tree. More...
 
 expandLevel ($level)
 Expand tree to level $level.
 
 packTree ($tree_id)
 Pack node numbers (NR).
 
- 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...
 
 addEvent ($name, $callback)
 Add event handler to $object->$name property. More...
 
 toArray ()
 Convert object to array. More...
 

Data Fields

 $db
 var Db Link to database object. More...
 
 $translator
 var Translator
 
 $nodes = array()
 Flat array of tree nodes. More...
 
 $patternLink = "<li id=\"{ID}\" {ATTR}><span><a href=\"{URL}\">{LABEL}</a></span></li>"
 Pattern for tree node with URL. More...
 
 $pattern = "<li id=\"{ID}\" {ATTR}><span>{LABEL}</span></li>"
 Pattern for tree node. More...
 
 $table = 'TREE_LOOKUPS'
 Database table for storing tree data. More...
 
 $CELL_SEPAR = '|'
 Separator of cells in tree text file.
 
 $LEVEL_SEPAR = '/'
 Separator of tree levels in tree text file.
 
- Data Fields inherited from BaseObject
 $onNewInstance
 Occurs when new instance of the class is created. More...
 
 $onMissingMethod
 Occurs when called method does not exist. More...
 
 $serviceLocator
 var function() Return service object when requested with service(). More...
 

Protected Member Functions

 currentIndex ()
 Return current index to Tree::nodes array.
 
 htmlListBegin ($level)
 Generate HTML for list open tag - UL.
 
 htmlTree ($level=0)
 Generate tree HTML. More...
 
 htmlListNode ($node)
 Generate HTML for tree node - LI. More...
 
 expandPath ($node_key)
 Expand (open) current tree to node $node_key. More...
 
 nextNode ($node_id)
 Return next node with level <= level of $node_id. More...
 
 makeGap (array $node, $n_nodes=1, $before=false)
 Make $n_nodes gap before/after $node. More...
 
- Protected Member Functions inherited from BaseObject
 fireEvent ($name, array $args=array())
 Run all event handlers in $object->$name property. More...
 
 service ($service, $default=null)
 Try acquire $service and load it into property $this->$service. More...
 

Protected Attributes

 $router
 var Router
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseObject
static defaults ()
 Set or retireve default parameters of the object. More...
 

Detailed Description

Load tree structure and render it as unordered list (ul).

Features:

Constructor & Destructor Documentation

__construct (   $cssClass = 'pctree')

Create Tree instance.

Parameters
string$cssClassCSS-class of the ul-tree.

Member Function Documentation

addChild (   $node_id,
array  $node 
)

Insert node $node as child of $node_id.

Parameters
int$node_idNode in database table
array$nodeTree node
Returns
int $node_id Id of added node
addChildren (   $node_id,
array  $nodes 
)

Add children to node_id.

Parameters
int$node_idNode id in database table
array$nodesFlat array of nodes
addNode (   $node_id,
array  $node 
)

Insert node $node after $node_id.

Parameters
int$node_idNode in database table
array$nodeTree node
Returns
int $node_id Id of added node
addNodeBefore (   $node_id,
array  $node 
)

Insert node $node before $node_id.

Parameters
int$node_idNode in database table
array$nodeTree node
Returns
int $node_id Id of added node
addSubTree (   $node_id)

Add current tree as subtree of $node_id.

Parameters
int$node_idTree is added under $snode_id into database table
See also
addtree()
addTree (   $tree_id,
  $node_id = null 
)

Add current tree to the database table.

Parameters
int$tree_idUnique id of the tree
int$node_idIf set, tree is added under $node_id as subtree
expand ( )

Expand path(s) in current tree.

Parameters
int|arrayId of nodes, which should be expanded (opened) Ex: $tree->expand(1,4,20) Expand tree to nodes 1,4,20
expandPath (   $node_key)
protected

Expand (open) current tree to node $node_key.

Parameters
int$node_keyKey in Tree::nodes array
See also
expand()
getChildren (   $node_id)

Return children of node_id as flat array.

Parameters
int$node_idNode id in database table
Returns
array $nodes Flat array of nodes
getSubTree (   $node_id,
  $maxlevel = null 
)

Load subtree of node $node_id from table Tree::table.

Parameters
int$node_idTree node
int$maxlevelLoad tree up to level $maxlevel
See also
gettree()
getTree (   $tree_id,
  $node_id = null,
  $maxlevel = null 
)

Load tree $tree_id from table Tree::table.

Parameters
int$tree_idUnique id of the tree
int$node_idIf set, this will load subtree of node $node_id
int$maxlevelLoad tree up to level $maxlevel
html ( )

Return HTML of current tree.

Build tree from Tree::nodes and return HTML.

htmlListNode (   $node)
protected

Generate HTML for tree node - LI.

Tree::pattern and Tree::pattern_link are used for drawing.

Parameters
array$nodeTree node (must contain LABEL, LEVEL)
Returns
string $html Node html code
See also
htmltree()
htmlTree (   $level = 0)
protected

Generate tree HTML.

Recursive function.

Parameters
array$nodesFlat array of tree nodes
int$levelCurrent tree level
Returns
string $html Tree html code
load (   $fileName)

Load tree from the text file.

The file is simple CSV file, containing columns for path and url. Path to the each node are labels separated with slash '/'.

Parameters
string$fileNamePath to csv-file
makeGap ( array  $node,
  $n_nodes = 1,
  $before = false 
)
protected

Make $n_nodes gap before/after $node.

Used before adding new nodes in the middle.

nextNode (   $node_id)
protected

Return next node with level <= level of $node_id.

See also
getSubTree()
out ( )

Print current tree.

Build tree from Tree::nodes and print it.

rmChildren (   $node_id)

Remove children of node_id from database table.

Parameters
int$node_idNode id in database table
rmNode (   $node_id)

Remove node from database table.

Parameters
int$node_idNode id in database table
setString (   $str)

Load tree from the text string.

Parameters
string$strString with tree definition
See also
load()

Field Documentation

$db

var Db Link to database object.

$nodes = array()

Flat array of tree nodes.

$pattern = "<li id=\"{ID}\" {ATTR}><span>{LABEL}</span></li>"

Pattern for tree node.

$patternLink = "<li id=\"{ID}\" {ATTR}><span><a href=\"{URL}\">{LABEL}</a></span></li>"

Pattern for tree node with URL.

$table = 'TREE_LOOKUPS'

Database table for storing tree data.


The documentation for this class was generated from the following file: