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

Class: treeClass

Source Location: /Tree-0.3.7/docs/TreeEditor/treeClass.php

Class Overview

Tree_Common
   |
   --Tree_Memory
      |
      --treeClass

this class can be used to step through a tree using ['parent'],['child']


Author(s):

Version:

  • 2001/06/27

Methods


Inherited Variables

Inherited Methods

Class: Tree_Memory

Tree_Memory::Tree_Memory()
set up this object
Tree_Memory::add()
adds _one_ new element in the tree under the given parent
Tree_Memory::addNode()
Adds multiple elements. You have to pass those elements in a multidimensional array which represents the tree structure as it shall be added (this array can of course also simply contain one element).
Tree_Memory::buildStructure()
builds the structure in the parameter $insertIn this function works recursively down into depth of the folder structure it builds an array which goes as deep as the structure goes
Tree_Memory::copy()
NOT IMPLEMENTED YET copies a part of the tree under a given parent
Tree_Memory::getChild()
returns the child if the node given has one !!! ATTENTION watch out that you never change any of the data returned, since they are references to the internal property $data
Tree_Memory::getChildren()
returns the children of the given ids
Tree_Memory::getElementByPath()
gets an element given by it's path as a reference
Tree_Memory::getFirstRoot()
this gets the first element that is in the root node
Tree_Memory::getIdByPath()
return the id of the element which is referenced by $path
Tree_Memory::getLevel()
get the level, which is how far below the root are we?
Tree_Memory::getNext()
returns the next element if the node given has one !!! ATTENTION watch out that you never change any of the data returned, since they are references to the internal property $data
Tree_Memory::getNode()
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
Tree_Memory::getParent()
returns the child if the node given has one !!! ATTENTION watch out that you never change any of the data returned, since they are references to the internal property $data
Tree_Memory::getPath()
gets the path to the element given by its id !!! ATTENTION watch out that you never change any of the data returned, since they are references to the internal property $data
Tree_Memory::getPrevious()
returns the previous element if the node given has one !!! ATTENTION watch out that you never change any of the data returned, since they are references to the internal property $data
Tree_Memory::getRoot()
since in a nested tree there can only be one root
Tree_Memory::isNode()
returns if the given element is a valid node
Tree_Memory::move()
move an entry under a given parent or behind a given entry.
Tree_Memory::remove()
removes the given node and all children if removeRecursively is on
Tree_Memory::setRemoveRecursively()
sets the remove-recursively mode, either true or false
Tree_Memory::setup()
Tree_Memory::setupByRawData()
Tree_Memory::switchDataSource()
use this to switch data sources on the run
Tree_Memory::update()
update data in a node
Tree_Memory::varDump()
this is for debugging, dumps the entire data-array an extra method is needed, since this array contains recursive elements which make a normal print_f or var_dump not show all the data
Tree_Memory::walk()
this method only serves to call the _walk method and reset $this->walkReturn that will be returned by all the walk-steps
Tree_Memory::_move()
this method moves one tree element
Tree_Memory::_remove()
collects the ID's of the elements to be removed

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 12]
this class can be used to step through a tree using ['parent'],['child']

the tree is saved as flat data in a db, where at least the parent needs to be given if a previous member is given too then the order on a level can be determined too actually this class was used for a navigation tree now it is extended to serve any kind of tree you can unambigiously refer to any element by using the following syntax tree->data[currentId][<where>]...[<where>] <where> can be either "parent", "child", "next" or "previous", this way you can "walk" from any point to any other point in the tree by using <where> in any order you want example (in parentheses the id): root +---level 1_1 (1) | +----level 2_1 (2) | +----level 2_2 (3) | +-----level 3_1 (4) +---level 1_2 (5)

the database table to this structure (without defined order) id parentId name

  1. 0 level 1_1
  2. 1 level 2_1
  3. 1 level 2_1
  4. 3 level 3_1
  5. 0 level 1_2
now you can refer to elements for example like this (all examples assume you know the structure): go from "level 3_1" to "level 1_1": $tree->data[4]['parent']['parent'] go from "level 3_1" to "level 1_2": $tree->data[4]['parent']['parent']['next'] go from "level 2_1" to "level 3_1": $tree->data[2]['next']['child'] go from "level 2_2" to "level 2_1": $tree->data[3]['previous'] go from "level 1_2" to "level 3_1": $tree->data[5]['previous']['child']['next']['child']

on a pentium 1.9 GHz 512 MB RAM, Linux 2.4, Apache 1.3.19, PHP 4.0.6 performance statistics for version 1.26, using examples/Tree/Tree.php

  • reading from DB and preparing took: 0.14958894252777
  • building took: 0.074488043785095
  • buildStructure took: 0.05151903629303
  • setting up the tree time: 0.29579293727875
  • number of elements: 1564
  • deepest level: 17
so you can use it for tiny-big trees too :-) but watch the db traffic, which might be considerable, depending on your setup.

FIXXXME there is one really bad thing about the entire class, at some points there are references to $this->data returned, or the programmer can even access this->data, which means he can change the structure, since this->data can not be set to read-only, therefore this->data has to be handled with great care!!! never do something like this:

  1.  $x &$tree->data[<some-id>]$x $y;
this overwrites the element in the structure !!!



[ Top ]


Method Detail

getAll   [line 24]

void &getAll( )

just a wrapper to be compatible to vp_DB_Common

[ Top ]

getAllVisible   [line 71]

array getAllVisible( )

this returns all the visible projects, the folders returned

are those which are unfolded, the explorer-like way it also handles the 'unfold' parameter, which we simply might be given so the unfold/fold works on every page that shows only visible folders i think that is really cool :-)

  • Return: only those folders which are visible

[ Top ]

getPathAsString   [line 15]

void getPathAsString( $id)


Overrides Tree_Common::getPathAsString() (returns the path as a string)

Parameters:

   $id   — 

[ Top ]

unfoldHandler   [line 77]

void unfoldHandler( )


[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:47:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.