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

Class: Tree_Dynamic_DBnested

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

Class Overview

Tree_Common
   |
   --Tree_OptionsDB
      |
      --Tree_Dynamic_DBnested

This class implements methods to work on a tree saved using the nested tree model.


Author(s):

Version:

  • 2001/06/27

Variables

Methods


Child classes:

Inherited Variables

Inherited Methods

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_Common

Tree_Common::getAllChildren()
gets all the children and grand children etc.
Tree_Common::getAllChildrenIds()
gets all the children-ids and grand children-ids
Tree_Common::getChildId()
Tree_Common::getChildrenIds()
get the ids of the children of the given element
Tree_Common::getDepth()
return the maximum depth of the tree
Tree_Common::getFirstRootId()
Tree_Common::getIdByPath()
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::getOption()
Tree_Common::getOptions()
returns all the options
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 it simply returns the ids of the elements returned by getParents()
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::hasChildren()
returns if the given element has any children
Tree_Common::isChildOf()
returns if $childId is a child of $id
Tree_Common::setOption()
Tree_Common::setOptions()
set a number of options which are simply given in an array
Tree_Common::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_Common::_getAllChildren()
this method gets all the children recursively

Class Details

[line 31]
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 35]


Type:   mixed


[ Top ]

$options = array(
        // FIXXME to be implemented
        // add on for the where clause, this string is simply added
        // behind the WHERE in the select so you better make sure
        // its correct SQL :-), i.e. 'uid=3'
        // this is needed i.e. when you are saving many trees in one db-table
        'whereAddOn'=>'',
        'table'     =>'',
        // since the internal names are fixed, to be portable between different
        // DB tables with different column namings, we map the internal name
        // to the real column name using this array here, if it stays empty
        // the internal names are used, which are:
        // id, left, right
        'columnNameMaps'=>array(
                            // since mysql at least doesnt support 'left' ...
                            'left'      =>  'l',
                            // ...as a column name we set default to the first
                            //letter only
                            'right'     =>  'r',
                            // parent id
                            'parentId'  =>  'parent'
                       ),// needed for sorting the tree, currently only used in Memory_DBnested
'order'=>'')

[line 37]


Type:   mixed
Overrides:   Array


[ Top ]



Method Detail

Tree_Dynamic_DBnested (Constructor)   [line 99]

void Tree_Dynamic_DBnested( string $dsn, [ $options = array()])


Parameters:

string   $dsn     the DSN for the DB connection
   $options     

[ Top ]

__construct (Constructor)   [line 82]

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


Parameters:

string   $dsn     the DSN for the DB connection
   $options     

[ Top ]

add   [line 146]

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 Method 1: Give only the $parentId and the $newValues will be inserted as the first child of this parent

  1.  // insert a new element under the parent with the ID=7
  2.  $tree->add(array('name'=>'new element name')7);

Method 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

  1.  // insert a new element after the element with the ID=5
  2.  $tree->add(array('name'=>'new')05);

Method 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!

  • Return: the ID of the element that had been inserted
  • Author: Wolfram Kriesing <wolfram@kriesing.de>
  • Access: public

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 621]

boolean copy( integer $id, [integer $parentId = 0], [integer $prevId = 0])

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

Parameters:

integer   $id     the ID of the node that shall be copied
integer   $parentId     the new parent ID
integer   $prevId     the new previous ID, if given parent ID will be omitted

[ Top ]

getChild   [line 699]

mixed getChild( integer $id)

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

Parameters:

integer   $id     the ID of the element for which the children shall be returned

[ Top ]

getChildren   [line 895]

mixed getChildren( mixed $ids, [integer $levels = 1])

get the children of the given element or if the parameter is an array.

It gets the children of all the elements given by their ids in the array.

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

Parameters:

mixed   $ids     (1) int the id of one element (2) array an array of ids for which the children will be returned
integer   $levels     the children of how many levels shall be returned

[ Top ]

getDepth   [line 1077]

integer getDepth( )

return the maximum depth of the tree
  • Return: the depth of the tree
  • Author: "Denis Joloudov" <dan@aitart.ru>, Wolfram Kriesing <wolfram@kriesing.de>
  • Version: 2003/02/25
  • Access: public

Overrides Tree_Common::getDepth() (return the maximum depth of the tree)
[ Top ]

getElement   [line 668]

mixed getElement( integer $id)

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

Parameters:

integer   $id     the ID of the element to return

[ Top ]

getFirstRoot   [line 1244]

void getFirstRoot( )


[ Top ]

getIdByPath   [line 1141]

integer getIdByPath( string $path, [integer $startId = 0], [string $nodeName = 'name'], [ $separator = '/'], string $seperator)

return the id of the element which is referenced by $path

this is useful for xml-structures, like: getIdByPath('/root/sub1/sub2') this requires the structure to use each name uniquely if this is not given it will return the first proper path found i.e. there should only be one path /x/y/z experimental: the name can be non unique if same names are in different levels

  • Return: the id of the searched element
  • Author: Pierre-Alain Joye <paj@pearfr.org>
  • Version: 2003/05/11
  • Access: public

Overrides Tree_Common::getIdByPath() (parent method not documented)

Parameters:

string   $path     the path to search for
integer   $startId     the id where to start the search
string   $nodeName     the name of the key that contains the node name
string   $seperator     the path seperator
   $separator     

[ Top ]

getLeft   [line 793]

mixed getLeft( integer $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 <wolfram@kriesing.de>
  • Version: 2002/03/07
  • Access: public

Parameters:

integer   $id     the ID of the element

[ Top ]

getLevel   [line 769]

void getLevel( $id)


Overrides Tree_Common::getLevel() (get the level, which is how far below the root the element with the given id is)

Parameters:

   $id     

[ Top ]

getNext   [line 971]

mixed getNext( integer $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 <wolfram@kriesing.de>
  • Version: 2002/04/15
  • Access: public

Parameters:

integer   $id     the ID of the element

[ Top ]

getNode   [line 1267]

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 <wolfram@kriesing.de>
  • Version: 2001/12/17
  • See: &_getNode()
  • Access: public

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 855]

mixed getParent( integer $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 <wolfram@kriesing.de>
  • Version: 2002/04/15
  • Access: public

Parameters:

integer   $id     the ID of the element

[ Top ]

getPath   [line 734]

mixed getPath( integer $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 <wolfram@kriesing.de>
  • Version: 2002/03/02
  • Access: public

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

Parameters:

integer   $id     the ID of the element for which the path shall be returned

[ Top ]

getPrevious   [line 1012]

mixed getPrevious( integer $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 <wolfram@kriesing.de>
  • Version: 2002/04/15
  • Access: public

Parameters:

integer   $id     the ID of the element

[ Top ]

getRight   [line 824]

mixed getRight( integer $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 <wolfram@kriesing.de>
  • Version: 2002/03/07
  • Access: public

Parameters:

integer   $id     the ID of the element

[ Top ]

getRoot   [line 642]

mixed getRoot( )

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

[ Top ]

hasChildren   [line 1113]

boolean hasChildren( integer $id)

Tells if the node with the given ID has children.
  • Return: if the node with the given id has children
  • Author: Wolfram Kriesing <wolfram@kriesing.de>
  • Version: 2003/03/04
  • Access: public

Overrides Tree_Common::hasChildren() (returns if the given element has any children)

Parameters:

integer   $id     the ID of a node

[ Top ]

isChildOf   [line 1052]

boolean isChildOf( int $id, int $childId)

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

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 404]

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 <wolfram@kriesing.de>
  • Version: 2002/06/08
  • Access: public

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 280]

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
  • Return: returns either true or throws an error
  • Author: Wolfram Kriesing <wolfram@kriesing.de>
  • Access: public

Parameters:

integer   $id     the id of the element to be removed

[ Top ]

update   [line 582]

mixed update( int $id, array $newValues)

update the tree element given by $id with the values in $newValues
  • Return: either true or an Tree_Error
  • Author: Wolfram Kriesing <wolfram@kriesing.de>
  • Access: public

Parameters:

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

[ Top ]

_move   [line 439]

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 ]


Documentation generated on Wed, 04 Jan 2012 03:00:18 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.