Tree
[ class tree: Tree ] [ index: Tree ] [ all elements ]

Class: Tree_Dynamic_DBnested

Source Location: /Tree-0.1.1/Dynamic/DBnested.php

Class Overview

PEAR
   |
   --Tree_Options
      |
      --Tree_OptionsDB
         |
         --Tree_Common
            |
            --Tree_Dynamic_DBnested

this class implements methods to work on a tree saved using the nested tree model explaination: http://research.calacademy.org/taf/proceedings/ballew/index.htm


Author(s):

Version:

  • 2001/06/27

Variables

Methods


Child classes:

Inherited Variables

Inherited Methods

Class: Tree_Common

Tree_Common::getChildId()
Tree_Common::getChildrenIds()
get the ids of the children of the given element
Tree_Common::getFirstRootId()
Tree_Common::getLeftId()
Tree_Common::getLevel()
get the level, which is how far below the root the element with the given id is
Tree_Common::getNextId()
Tree_Common::getParentId()
get the id of the parent for the given element
Tree_Common::getParents()
this gets all the preceeding nodes, the parent and it's parent and so on
Tree_Common::getParentsIds()
get the ids of the parents and all it's parents and so on
Tree_Common::getPath()
gets the path to the element given by its id
Tree_Common::getPathAsString()
returns the path as a string
Tree_Common::getPreviousId()
Tree_Common::getRightId()
Tree_Common::getRootId()
Tree_Common::isChildOf()
returns if $childId is a child of $id

Class: Tree_OptionsDB

Tree_OptionsDB::Tree_OptionsDB()
this constructor sets the options, since i normally need this and in case the constructor doesnt need to do anymore i already have it done :-)

Class: Tree_Options

Tree_Options::Tree_Options()
this constructor sets the options, since i normally need this and in case the constructor doesnt need to do anymore i already have it done :-)
Tree_Options::getOption()
Tree_Options::getOptions()
returns all the options
Tree_Options::setOption()
Tree_Options::setOptions()
set a number of options which are simply given in an array

Class Details

[line 32]
this class implements methods to work on a tree saved using the nested tree model explaination: http://research.calacademy.org/taf/proceedings/ballew/index.htm


[ Top ]


Class Variables

$debug =  0

[line 37]


Type:   mixed


[ Top ]

$options = array(
                            'whereAddOn'=>''                                                                                                                                ,'table'     =>''                                                                                                                                               ,'columnNameMaps'=>array(
                                                                                                 'left'          =>  'l'                                                            ,'right'         =>  'r'                                                                                                            ,'parentId'       =>  'parent'                                                    ),'order'=>'')

[line 39]


Type:   mixed
Overrides:   Array


[ Top ]



Method Detail

Tree_Dynamic_DBnested (Constructor)   [line 88]

Tree_Dynamic_DBnested Tree_Dynamic_DBnested( mixed $dsn, [mixed $options = array()])


[ Top ]

add   [line 122]

integer add( array $newValues, [integer $parentId = 0], [integer $prevId = 0])

add a new element to the tree there are three ways to use this method 1.

give only the $parentId and the $newValues will be inserted as the first child of this parent i.e. // insert a new element under the parent with the ID=7 $tree->add( array('name'=>'new element name') , 7 ); 2. give the $prevId ($parentId will be dismissed) and the new element will be inserted in the tree after the element with the ID=$prevId the parentId is not necessary because the prevId defines exactly where the new element has to be place in the tree, and the parent is the same as for the element with the ID=$prevId i.e. // insert a new element after the element with the ID=5 $tree->add( array('name'=>'new') , 0 , 5 ); 3. neither $parentId nor prevId is given, then the root element will be inserted this requires that programmer is responsible to confirm this this method does not (yet) check if there is already a root element saved !!!


Parameters:

array   $newValues     this array contains the values that shall be inserted in the db-table
integer   $parentId     the id of the element which shall be the parent of the new element
integer   $prevId     the id of the element which shall preceed the one to be inserted use either 'parentId' or 'prevId'

[ Top ]

copy   [line 556]

void copy( mixed $id, mixed $parentId, mixed $prevId)

copy a subtree/node/... under a new parent or/and behind a given element

[ Top ]

getChild   [line 620]

mixed getChild( mixed $id)

  • Return: either the data of the requested element or an Tree_Error
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2002/03/02
  • Access: public

[ Top ]

getChildren   [line 762]

mixed getChildren( mixed $id)

get the children of the given element
  • Return: the array with the data of all children or false, if there are none
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2002/04/15
  • Access: public

[ Top ]

getElement   [line 594]

mixed getElement( mixed $id)

  • Return: either the data of the requested element or an Tree_Error
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2002/03/02
  • Access: public

[ Top ]

getFirstRoot   [line 906]

void getFirstRoot( )


[ Top ]

getLeft   [line 680]

mixed getLeft( mixed $id)

gets the element to the left, the left visit
  • Return: either the data of the requested element or an Tree_Error
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2002/03/07
  • Access: public

[ Top ]

getNext   [line 793]

mixed getNext( mixed $id)

get the next element on the same level if there is none return false
  • Return: the array with the data of the next element or false, if there is no next or Tree_Error
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2002/04/15
  • Access: public

[ Top ]

getNode   [line 923]

array &getNode( [integer $startId = 0], [integer $depth = 0])

gets the tree under the given element in one array, sorted so you can go through the elements from begin to end and list them as they are in the tree, where every child (until the deepest) is retreived
  • Return: sorted as listed in the tree
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2001/12/17
  • Access: public
  • See: &_getNode()

Parameters:

integer   $startId     the id where to start walking
integer   $depth     this number says how deep into the structure the elements shall be retreived

[ Top ]

getParent   [line 736]

mixed getParent( mixed $id)

get the parent of the element with the given id
  • Return: the array with the data of the parent element or false, if there is no parent, if the element is the root or an Tree_Error
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2002/04/15
  • Access: public

[ Top ]

getPath   [line 651]

mixed getPath( mixed $id)

gets the path from the element with the given id down

to the root the returned array is sorted to start at root for simply walking through and retreiving the path

  • Return: either the data of the requested elements or an Tree_Error
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2002/03/02
  • Access: public

Overrides Tree_Common::getPath() (gets the path to the element given by its id)
[ Top ]

getPrevious   [line 825]

mixed getPrevious( mixed $id)

get the previous element on the same level if there is none return false
  • Return: the array with the data of the previous element or false, if there is no previous or a Tree_Error
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2002/04/15
  • Access: public

[ Top ]

getRight   [line 707]

mixed getRight( mixed $id)

gets the element to the right, the right visit
  • Return: either the data of the requested element or an Tree_Error
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2002/03/07
  • Access: public

[ Top ]

getRoot   [line 572]

mixed getRoot( )

get the root
  • Return: either the data of the root element or an Tree_Error
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Version: 2002/03/02
  • Access: public

[ Top ]

isChildOf   [line 856]

boolean isChildOf( int $id, int $childId)

returns if $childId is a child of $id
  • Return: true if it is a child
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Access: public
  • Version: 2002/04/29
  • Abstract:

Overrides Tree_Common::isChildOf() (returns if $childId is a child of $id)

Parameters:

int   $id     id of the element
int   $childId     id of the element to check if it is a child

[ Top ]

move   [line 357]

mixed move( integer $idsToMove, integer $newParentId, [integer $newPrevId = 0])

move an entry under a given parent or behind a given entry.

If a newPrevId is given the newParentId is dismissed! call it either like this: $tree->move( x , y ) to move the element (or entire tree) with the id x under the element with the id y or $tree->move( x , 0 , y ); // ommit the second parameter by setting it to 0 to move the element (or entire tree) with the id x behind the element with the id y or $tree->move( array(x1,x2,x3) , ... the first parameter can also be an array of elements that shall be moved the second and third para can be as described above If you are using the Memory_DBnested then this method would be invain, since Memory.php already does the looping through multiple elements, but if Dynamic_DBnested is used we need to do the looping here

  • Return: true for success, Tree_Error on failure
  • Author: Wolfram Kriesing <mailto:wolfram@kriesing.de>
  • Access: public
  • Version: 2002/06/08

Parameters:

integer   $idsToMove     the id(s) of the element(s) that shall be moved
integer   $newParentId     the id of the element which will be the new parent
integer   $newPrevId     if prevId is given the element with the id idToMove shall be moved _behind_ the element with id=prevId if it is 0 it will be put at the beginning

[ Top ]

remove   [line 253]

boolean remove( integer $id)

remove a tree element this automatically remove all children and their children if a node shall be removed that has children

Parameters:

integer   $id     the id of the element to be removed

[ Top ]

update   [line 520]

mixed update( int $id, array $newValues)

update the tree element given by $id with the values in $newValues

Parameters:

int   $id     the id of the element to update
array   $newValues     the new values, the index is the col name

[ Top ]

_move   [line 387]

mixed _move( integer $idToMove, integer $newParentId, [integer $newPrevId = 0])

this method moves one tree element

Parameters:

integer   $idToMove     the id of the element that shall be moved
integer   $newParentId     the id of the element which will be the new parent
integer   $newPrevId     if prevId is given the element with the id idToMove shall be moved _behind_ the element with id=prevId if it is 0 it will be put at the beginning

[ Top ]

__construct   [line 74]

void __construct( mixed $dsn, [mixed $options = array()])


[ Top ]


Documentation generated on Fri, 30 Apr 2004 21:33:49 +0200 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.