[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Tree/ -> Tree.php (sommaire)

(pas de description)

Poids: 1045 lignes (30 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 3 classes

Tree:: (15 méthodes):
  Tree()
  getRootNode()
  getChildrenCount()
  getNodeByID()
  sureGetNodeByID()
  getNodeByAlias()
  sureGetNodeByAlias()
  getNodeByHierarchy()
  hasChildren()
  getChildren()
  getFlatList()
  getFlattenedChildren()
  findNodeByTag()
  createFromList()
  merge()

Tree_Node:: (23 méthodes):
  Tree_Node()
  getContent()
  setTag()
  getTag()
  setUID()
  getUID()
  prevSibling()
  nextSibling()
  getSiblingCount()
  remove()
  setTree()
  getTree()
  setParent()
  getParent()
  getParentNode()
  hasChildren()
  getChildren()
  getChildrenCount()
  depth()
  getLevel()
  isChildOf()
  moveTo()
  copyTo()

Tree_NodeCollection:: (13 méthodes):
  Tree_NodeCollection()
  addNode()
  firstNode()
  lastNode()
  removeNodeAt()
  removeNode()
  indexOf()
  getNodeCount()
  getFlatList()
  traverse()
  search()
  moveTo()
  copyTo()


Classe: Tree  - X-Ref

An OO tree class based on various things, including the MS treeview control
If you use this class and wish to show your appreciation then visit my
wishlist here:   http://www.amazon.co.uk/exec/obidos/wishlist/S8H2UOGMPZK6

Structure of one of these trees:

Tree Object
|
+- Tree_NodeCollection object (nodes property)
|
+- Array of Tree_Node objects (nodes property)

Usage:
$tree = &new Tree();
$node  = &$tree->nodes->addNode(new Tree_Node('1'));
$node2 = &$tree->nodes->addNode(new Tree_Node('2'));
$node3 = &$tree->nodes->addNode(new Tree_Node('3'));
$node4 = &$node3->nodes->addNode(new Tree_Node('3_1'));
$tree->nodes->removeNodeAt(0);
print_r($tree);

The data for a node is supplied by giving it as the argument to the Tree_Node
constructor. You can retreive the data by using a nodes getTag() method, and alter
it using the setTag() method.

Public methods for Tree class:
hasChildren()                                            Returns whether this tree has child nodes or not
&createFromList(array data [, string separator])         (static) Returns a tree structure create from the supplied list
&createFromMySQL(array $params)                          (static) Returns a tree structure created using a common DB storage technique
&createFromXMLTree(object $xmlTree [, bool $ignoreRoot]) (static) Returns a tree structure created using an PEAR::XML_Tree object
&merge(object &$tree [, ...])                            Merges two or more Tree/Tree_Node objects. Can be used statically or not.

Public methods for Tree_Node class:
setTag(mixed tag)                                 Sets the tag data
getTag()                                          Retreives the tag data
&prevSibling()                                    Retreives a reference to the previous sibling node
&nextSibling()                                    Retreives a reference to the next sibling node
remove()                                          Removes this node from the collection
&getTree()                                        Returns the encompassing Tree object
&getParent()                                      Returns the parent Tree_Node object if any
hasChildren()                                     Returns whether this node has child nodes or not
depth()                                           Returns the depth of this node in the tree (zero based)
isChildOf()                                       Returns whether this node is a direct child of the given node/tree
moveTo()                                          Moves this node to be a child of the given node/tree
copyTo()                                          Copies this node to a new child of the given node/tree

Public variables for Tree_Node class:
$nodes

Public methods for Tree_NodeCollection class:
&addNode(Tree_Node node)                           Adds a node to the collection
&firstNode()                                       Retreives a reference to the first node in the collection
&lastNode()                                        Retreives a reference to the last node in the collection
&removeNodeAt(int index)                           Removes the node at the specified index (nodes are re-ordered)
removeNode(Tree_Node node [, boolean search])      Removes the given node (nodes are re-ordered)
indexOf(Tree_Node node)                            Retreives the index of the given node
getNodeCount([boolean recurse])                    Retreives the number of nodes in the collection, optionally recursing
getFlatList()                                      Retrieves an indexed array of the nodes from top to bottom, left to right
traverse(callback function)                        Traverses the tree supply each node to the callback function
search(mixed searchData [, bool strict])           Basic search function for searching the Trees' "tag" data
moveTo()                                           Moves the nodes in this collection to the given node/tree
copyTo()                                           Copies the nodes in this collection to the given node/tree
Tree()   X-Ref
Constructor


getRootNode()   X-Ref
Pas de description

getChildrenCount()   X-Ref
Pas de description

getNodeByID($id)   X-Ref
Pas de description

sureGetNodeByID($id)   X-Ref
Pas de description

getNodeByAlias($alias)   X-Ref
Pas de description

sureGetNodeByAlias($alias)   X-Ref
Pas de description

getNodeByHierarchy($position)   X-Ref
Pas de description

hasChildren()   X-Ref
Returns true/false as to whether this node
has any child nodes or not.

return: bool Any child nodes or not

getChildren()   X-Ref
Returns all the child nodes for this
node.

return: array All of the child nodes

getFlatList()   X-Ref
Pas de description

getFlattenedChildren()   X-Ref
Pas de description

findNodeByTag($tagname, &$col)   X-Ref
Returns a node anywhere in the tree given a tag name.
A null is returned if the node isn't found.

return: object The found node

createFromList($data, $separator = '/')   X-Ref
Creates a tree structure from a list of items.
Items must be separated using the supplied separator.
Eg:    array('foo',
'foo/bar',
'foo/bar/jello',
'foo/bar/jello2',
'foo/bar2/jello')

Would create a structure thus:
foo
+-bar
|  +-jello
|  +-jello2
+-bar2
+-jello

Example code:
$list = array('Foo/Bar/blaat', 'Foo', 'Foo/Bar', 'Foo/Bar/Jello', 'Foo/Bar/Jello2', 'Foo/Bar2/Jello/Jello2');
$tree = Tree::createFromList($list);

param: array  $data      The list as an indexed array
param: string $separator The separator to use
return: object            A tree structure (Tree object)

merge(&$tree)   X-Ref
Merges two or more tree structures into one. Can take either
Tree objects or Tree_Node objects as arguments to merge. This merge
simply means the nodes from the second+ argument(s) are added to
the first.

param: object $tree The Tree/Tree_Node object to merge subsequent
param: ...          Any number of Tree or Tree_Node objects to be merged
return: object      Resulting merged Tree/Tree_Node object

Classe: Tree_Node  - X-Ref

A node class to complement the above
tree class

Tree_Node($tag = null)   X-Ref
Constructor

param: mixed $tag The data that this node represents

getContent()   X-Ref
Gets the underlying content of this node


setTag($tag)   X-Ref
Sets the tag data

param: mixed $tag The data to set the tag to

getTag()   X-Ref
Returns the tag data

return: mixed The tag data

setUID(&$uid)   X-Ref
Sets the nodes UID

param: integer $uid The UID

getUID()   X-Ref
Returns the node UID

return: integer The UID

prevSibling()   X-Ref
Returns the previous child node in the parents node array,
or null if this node is the first.

return: object A reference to the previous node in the parent

nextSibling()   X-Ref
Returns the next child node in the parents node array,
or null if this node is the last.

return: object A reference to the next node in the parent

getSiblingCount()   X-Ref
Pas de description

remove()   X-Ref
Removes this node from its' parent. If this
node has no parent (ie its not been added to
a Tree or Tree_Node object) then this method
will do nothing.


setTree(&$tree)   X-Ref
Sets the master Tree object for this
node.

param: object $tree The Tree object reference

getTree()   X-Ref
Returns the tree object which this node is attached
to (if any).

return: object The encompassing Tree object

setParent(&$node)   X-Ref
Sets the parent node of the node.

param: object $node The parent node

getParent()   X-Ref
Returns the parent node if any

return: object The parent Tree_Node object

getParentNode()   X-Ref
Returns the parent node if any -- backwards compatible
with the old hierarchy manager code.

return: object The parent Tree_Node object

hasChildren()   X-Ref
Returns true/false as to whether this node
has any child nodes or not.

return: bool Any child nodes or not

getChildren()   X-Ref
Returns all the child nodes for this
node.

return: array All of the child nodes

getChildrenCount()   X-Ref
Pas de description

depth()   X-Ref
Returns the depth in the tree of this node
This is a zero based indicator, so root nodes
will have a depth of 0 (zero).

return: integer The depth of the node

getLevel()   X-Ref
Returns the depth in the tree.  This is to make this backwards
compatible with the old hierarchy manager.

return: integer The depth of the node.

isChildOf($parent)   X-Ref
Returns true/false as to whether this node is a child
of the given node.

param: object $parent The suspected parent Tree_Node object
return: bool           Whether this node is a child of the suspected parent

moveTo(&$newParent)   X-Ref
Moves this node to a new parent. All child nodes will
be retained.

param: object $newParent The new parent Tree_Node or Tree object

copyTo(&$newParent)   X-Ref
Copies this node to a new parent. This copies the node
to the new parent node/tree and all its child nodes (ie
a deep copy). Technically, new nodes are created with copies
of the tag data, since this is for all intents and purposes
the only thing that needs copying.

param: object $newParent The new parent Tree_Node or Tree object
return: object            The new node

Classe: Tree_NodeCollection  - X-Ref

A class to represent a collection of child nodes

Tree_NodeCollection(&$container)   X-Ref
Constructor


addNode(&$node)   X-Ref
Adds a node to this node

param: object $node The Tree_Node object
return: object       A reference to the new node inside the tree

firstNode()   X-Ref
Returns the first node in this particular collection

return: object The first node. NULL if no nodes.

lastNode()   X-Ref
Returns the last node in this particular collection

return: object The last node. NULL if no nodes.

removeNodeAt($index)   X-Ref
Removes a node from the child nodes array at the
specified (zero based) index.

return: object         The node that was removed, or null

removeNode(&$node, $search = false)   X-Ref
Removes a node from the child nodes array by using
the unique ID stored in each instance

param: object $node   The node to remove
param: bool   $search Whether to search child nodes
return: bool           True/False

indexOf($node)   X-Ref
Returns the index in the nodes array at which
the given node resides. Used in the prev/next Sibling
methods.

param: object $node The node to return the index of
return: integer      The index of the node or null if

getNodeCount($search = false)   X-Ref
Returns the number of child nodes in this node/tree.
Optionally searches the tree and returns the cumulative count.

param: bool    $search Search tree for nodecount too
return: integer         The number of nodes found

getFlatList()   X-Ref
Returns a flat list of the node collection. This array contains references
to the nodes.

return: array Flat list of the nodes from top to bottom, left to right.

traverse($function)   X-Ref
Traverses the node collection applying a function to each and every node.
The function name given (though this can be anything you can supply to
call_user_func(), not just a name) should take a single argument which is the
node object (Tree_Node class). You can then access the nodes data by using
the getTag() method. The traversal goes from top to bottom, left to right
(ie same order as what you get from getFlatList()).

** The node is passed by reference to the function! **

param: callback $function The callback function to use

search(&$data, $strict = false)   X-Ref
Searches the node collection for a node with a tag matching
what you supply. This is a simply "tag == your data" comparison, (=== if strict option is applied)
and more advanced comparisons can be made using the traverse() method.
This function returns null if nothing is found, and a reference to the
first found node if a match is made.

param: mixed $data   Data to try to find and match
param: mixed $strict Whether to use === or simply == to compare
return: mixed         Null if no match, a reference to the first found node

moveTo(&$newParent)   X-Ref
Moves the nodes in this collection (not the collection itself)
to the given new parent.

param: object $newParent The new parent Tree_Node or Tree object

copyTo(&$newParent)   X-Ref
Copies the nodes in this collection (not the collection itself)
to the given new parent.

param: object $newParent The new parent Tree_Node or Tree object



Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7