Class SGL_NestedSet

Description

A lightweight wrapper to PEAR DB_NestedSet that bypasses NestedSet for most methods, querying the specified nested set table directly via PEAR DB; more complex, write-heavy methods are left to DB_NestedSet.

Located in /SGL/NestedSet.php (line 50)


	
			
Variable Summary
 mixed $params
 mixed $_aNodes
 array $_images
Method Summary
 SGL_NestedSet SGL_NestedSet ( $params)
 void addImages ( &$aNodes, array $aNodes)
 void createLeftNode ( $id,  $values)
 void createRightNode ( $id,  $values)
 void createRootNode ( $values, [ $id = false], [ $first = false], [ $pos = 'AF'])
 void createSubNode ( $id,  $values)
 void deleteNode ( $id)
 array getBranch (int $node_id, [ $addSQL = array()])
 array getBreadcrumbs (int $node_id, [ $addSQL = array()], [ $includeCurrentNode = false])
 array getChildren (int $node_id, [ $addSQL = array()])
 array getNode (int $node_id)
 void getParent ( $id)
 array getRoots ([void $addSQL = array()])
 array getSubBranch (int $node_id, [ $addSQL = array()])
 array getTree ([void $addSQL = array()])
 void moveTree ( $id,  $targetid,  $pos, [ $copy = false])
 object DB_NestedSet_DB prepareValues ( $values, [ $quoteValues = false])
 void setImage ( $key,  $value)
 void setImages ( $imagesArray)
 void &singleton ( $params)
 DB_OK updateNode (int $id, array $values)
 void _addSQL ( $addSQL,  $type, [ $prefix = false])
 void _cleanMemoryCache ([integer $id = null])
 void &_getDb ()
 object DB_NestedSet_DB _getNestedSet ()
Variables
mixed $params = array('tableStructure' =>
array(
'id' => 'id',
'rootid' => 'rootid',
'l' => 'l',
'r' => 'r',
'norder' => 'norder',
'level' => 'level',
'parent' => 'parent'
),'tableName'=>'','lockTableName'=>'','sequenceName'=>'')
(line 72)
mixed $_aNodes = array() (line 86)
array $_images = array(
'upArrow' => 'images/16/move_up.gif',
'upArrowDead' => 'images/16/move_up_dead.gif',
'downArrow' => 'images/16/move_down.gif',
'downArrowDead' => 'images/16/move_down_dead.gif',
'folder' => 'images/treeNav/foldericon.png',
'file' => 'images/treeNav/file.png',
'blank' => 'images/treeNav/blank.png',
't' => 'images/treeNav/T.png',
'l' => 'images/treeNav/L.png',
'i' => 'images/treeNav/I.png')
(line 58)

Array of images for addImages() to use to decorate results, relative to root.

  • access: private
mixed $_protectedFields = array('id', 'rootid', 'l', 'r', 'norder', 'level', 'parent') (line 70)
Methods
Constructor SGL_NestedSet (line 100)
SGL_NestedSet SGL_NestedSet ( $params)
  • $params
addImages (line 449)

Takes a reference to a nodes array such as returned by getTree() et. al. and adds to

each node array an array of images that can be used to build a MS Windows Explorer-like tree view, with images for file, folder, blank, and I, L, and T shapes, as well as up and down arrows that are grayed out when the node cannot be moved up or down (has no siblings above or below it).

void addImages ( &$aNodes, array $aNodes)
  • array $aNodes
  • &$aNodes
createLeftNode (line 638)
void createLeftNode ( $id,  $values)
  • $id
  • $values
createRightNode (line 646)
void createRightNode ( $id,  $values)
  • $id
  • $values
createRootNode (line 624)

The following are all just wrappers to DB_NestedSet, an instance of which is returned by _getNestedSet(). See PEAR/DB/NestedSet.php for API docs.

void createRootNode ( $values, [ $id = false], [ $first = false], [ $pos = 'AF'])
  • $values
  • $id
  • $first
  • $pos
createSubNode (line 630)
void createSubNode ( $id,  $values)
  • $id
  • $values
deleteNode (line 662)
void deleteNode ( $id)
  • $id
getBranch (line 221)

For any node whose id is supplied, fetches branch for that node (all nodes with same root_id), including that node, and those above and below it.

  • return: of node arrays
  • author: Andy Crain <andy@newslogic.com>
  • version: 1.0
  • since: PHP 4.0
  • access: public
array getBranch (int $node_id, [ $addSQL = array()])
  • int $node_id
  • $addSQL
getBreadcrumbs (line 396)

Returns "breadcrumbs," a node's ancestral path through the tree: same rootid, and a level less than this node's, and a left node less than this node's, and a right node greater than this node's.

  • return: of node arrays
  • author: Andy Crain <andy@newslogic.com>
  • version: 1.0
  • since: PHP 4.0
  • access: public
array getBreadcrumbs (int $node_id, [ $addSQL = array()], [ $includeCurrentNode = false])
  • int $node_id
  • $addSQL
  • $includeCurrentNode
getChildren (line 302)

For any node, fetches child nodes (nodes with same rootid, with level = parent level + 1, with l between parent's l and r).

  • return: of node arrays
  • author: Andy Crain <andy@newslogic.com>
  • version: 1.0
  • since: PHP 4.0
  • access: public
array getChildren (int $node_id, [ $addSQL = array()])
  • int $node_id
  • $addSQL
getNode (line 365)

Returns the node indentified by supplied id, or false.

  • return: | false
  • author: Andy Crain <andy@newslogic.com>
  • version: 1.0
  • since: PHP 4.0
  • access: private
array getNode (int $node_id)
  • int $node_id
getParent (line 284)
void getParent ( $id)
  • $id
getRoots (line 144)

Fetches all root nodes (rootid = id) from the entire table/tree.

  • return: of node arrays
  • author: Andy Crain <andy@newslogic.com>
  • version: 1.0
  • since: PHP 4.0
  • access: public
array getRoots ([void $addSQL = array()])
  • void $addSQL
getSubBranch (line 257)

For any node, fetches all descendents (kids, grandkids, etc.)of that node (nodes with same rootid and with left ids bounded by this node's left and right id, and which aren't this node).

  • return: of node arrays
  • author: Andy Crain <andy@newslogic.com>
  • version: 1.0
  • since: PHP 4.0
  • access: public
array getSubBranch (int $node_id, [ $addSQL = array()])
  • int $node_id
  • $addSQL
getTree (line 180)

Fetches all nodes from all roots, i.e., the entire table/tree.

  • return: of node arrays
  • author: Andy Crain <andy@newslogic.com>
  • version: 1.0
  • since: PHP 4.0
  • access: public
array getTree ([void $addSQL = array()])
  • void $addSQL
moveTree (line 654)
void moveTree ( $id,  $targetid,  $pos, [ $copy = false])
  • $id
  • $targetid
  • $pos
  • $copy
prepareValues (line 549)

Prepares $values array for insert or update into table. Called with $quoteValues=true to build quoted key=value strings for update sql.

Called externally with $quoteValues=false to simply weed out of an array any fields that either are not in the table or that are but are internal.

object DB_NestedSet_DB prepareValues ( $values, [ $quoteValues = false])
  • $values
  • $quoteValues
setImage (line 122)
void setImage ( $key,  $value)
  • $key
  • $value
setImages (line 128)
void setImages ( $imagesArray)
  • $imagesArray
singleton (line 88)
void &singleton ( $params)
  • $params
updateNode (line 520)

Updates defined fields (any field defined in params['tableStructure'] that is not a NestedSet field such as l, r, rootid, norder, etc. (i.e. not in _protectedFields).

  • return: | PEAR Error
  • author: Andy Crain <andy@newslogic.com>
  • version: 1.0
  • since: PHP 4.0
  • access: public
DB_OK updateNode (int $id, array $values)
  • int $id
  • array $values: (field name => field value)
_addSQL (line 339)

Borrowed from PEAR DB_NestedSet. Formats various sql clauses.

void _addSQL ( $addSQL,  $type, [ $prefix = false])
  • $addSQL
  • $type
  • $prefix
_cleanMemoryCache (line 675)

Clean nodes stored in memory

  • access: private
void _cleanMemoryCache ([integer $id = null])
  • integer $id: node id [optional]
_getDb (line 111)
void &_getDb ()
_getNestedSet (line 587)

DB_NestedSet_DB factory. Called only by wrapper methods.

Several methods (createRootNode() and moveTree()) when called from DB_NestedSet directly take constants as parameters, but since DB_NestedSet isn't instantiated at call time, we pass the constants' values instead. Values for $pos are: 'BE' (move node before target norder), 'AF' (move node after target norder), or 'SUB' (move node beneath, as a child to target). See PEAR DB_NestedSet docs for api info on wrapper methods.

object DB_NestedSet_DB _getNestedSet ()

Documentation generated on Tue, 23 Feb 2010 18:14:31 +0000 by phpDocumentor 1.4.3