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

Class: Tree_Memory_MDB2simple

Source Location: /Tree-0.3.7/Tree/Memory/MDB2simple.php

Class Overview

Tree_Common
   |
   --Tree_OptionsMDB2
      |
      --Tree_Memory_MDB2simple

the MDB2 interface to the tree class


Author(s):

Version:

  • 2001/06/27

Variables

Methods


Inherited Variables

Inherited Methods

Class: Tree_OptionsMDB2

Tree_OptionsMDB2::Tree_OptionsMDB2()
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 30]
the MDB2 interface to the tree class


[ Top ]


Class Variables

$options = array('order' => '',
                         'whereAddOn' => '',
                         'table' => '',
                         'columnNameMaps' => array(
                                   /* 'id'       => 'tree_id', // use "tree_id" as "id"
                                      'parentId' => 'parent_id',
                                      'prevId'   => 'previous_id',
                                      'name'     => 'nodeName'
                                   */
                        ),)

[line 52]

  • Var: saves the options passed to the constructor. Valid options:
    • order: which column to order by when reading the data from the DB, this sorts the data even inside every level
    • whereAddOn: 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 for different user in one table where each entry has a uid (user id)
    • columnNameMaps: the column-name maps are used for the "as" in the select queries so you can use any column name in the table and "map" it to the name that shall be used in the internal array, that is built, see the examples (in comments)
    • columnNameMaps: array for id/parentId/prevId/name table column names
  • Access: public

Type:   array
Overrides:   Array


[ Top ]

$table =

[line 69]

  • Var: the table where to read the tree data from can also be set using the DSN in the constructor
  • Access: public

Type:   string


[ Top ]



Method Detail

Tree_Memory_MDB2simple (Constructor)   [line 88]

Tree_Memory_MDB2simple Tree_Memory_MDB2simple( string $dsn, [array $options = array()])

set up this object
  • Access: public

Parameters:

string   $dsn     this is a DSN of the for that PEAR::DB uses it only that additionally you can add parameters like ...?table=test_table to define the table it shall work on
array   $options     additional options you can set

[ Top ]

add   [line 185]

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

adds _one_ new element in the tree under the given parent

the values' keys given have to match the db-columns, because the value gets inserted in the db directly to add an entire node containing children and so on see 'addNode()'

to be compatible with the MDB2nested, u can also give the parent and previd as the second and third parameter

  • Return: either boolean false on failure or the id of the inserted row
  • See: addNode
  • Access: public

Parameters:

array   $newValues     this array contains the values that shall be inserted in the db-table the key for each element is the name of the column
   $parentId     

[ Top ]

move   [line 270]

boolean move( integer $idToMove, integer $newParentId, [integer $newPrevId = 0])

move an entry under a given parent or behind a given entry
  • Return: true for success
  • Author: Wolfram Kriesing <wolfram@kriesing.de>
  • Version: 2001/10/10
  • Access: public

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 if no prevId is in the DB it can be 0 too and won't bother since it is not written in the DB anyway

[ Top ]

remove   [line 224]

boolean remove( mixed $id)

removes the given node
  • Return: true on success
  • Access: public

Parameters:

mixed   $id     the id of the node to be removed, or an array of id's to be removed

[ Top ]

setup   [line 109]

boolean setup( )

retrieve all the navigation data from the db and call build to build the tree in the array data and structure
  • Return: true on success
  • Access: public

[ Top ]

update   [line 308]

boolean update( $id, array $newData)

update an element in the DB
  • Return: true for success
  • Author: Wolfram Kriesing <wolfram@kriesing.de>
  • Version: 2002/01/17
  • Access: public

Parameters:

array   $newData     all the new data, the key 'id' is used to elements are the data to fill in the DB
   $id     

[ Top ]


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