Hi All,

        Below is a bit of a post that I found in the archives...

        Is the Spruce tree implimentation available somewhere?

Cheers,
Brad











From: Spruce Weber ([EMAIL PROTECTED])
Date: 09/21/00 

I've created from scratch a tree class that utilizes templates. What makes 
this class worth using is the fact that it uses templates and the ease with 
which it is extended. Heirarchical data is often stored in a database table 
as follows: 


record_id, parent_record_id, field_1, field_two, field_three... 


The only data my class requires for each record/branch is its ID and its 
parent's ID (or 0 if it's a top-level record/branch). The vars element can 
contain one or more var=>val pairs that can be used when parsing each branch

of the tree. Data returned by a query of a table in the above format can be 
easily prepared for use by my tree class as follows... 


While($db->next_record()) { 
  $data[$db->f("record_id")] = 
    array("parent" => $db->f("parent_record_id"), 
          "vars" => array("field_1"=>$db->f("field_1"), 
                            "field_2"=>$db->f("field_2"), 
                            "field_3"=>$db->f("field_3") 
                            )); 
} 


The following code will then parse and display the tree, complete with links

that will expand and collapse branches that have children. 



if(!$sess->is_registered("tree")) { 
  $tree = new Spruce_Tree("/some/directory"); 
  $sess->register("tree"); 
} 


if($sprout) $tree->sprout($sprout); // expand a branch 
if($prune) $tree->prune($prune); // collapse a branch 
$tree->set_tree_target("a_target"); // only necessary when using frames 
$tree->pparse($data); // parse tree and print results 


The branches can contain as much or as little data as you like depending on 
the fields you place in the template and the data you insert into each 
"vars" element. 


The only data that is stored in the session is the name of the template file

being used (spruce_tree.tpl by default), the directory in which the template

is located, and an array containing the IDs of branches that are currently 
expanded. 


Yes, my name is Spruce, and this is my Tree class! If there's any interest 
I'll be happy to share the implementation. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to