Proposal for Zend_Db_NestedSet – Hierarchical data as a nested set

Graham Anderson writes a very interesting proposal; If you are interested in an implementation of storing and retrieving hierarchical data as a nested set, please take a few minutes to review my new proposal[1].

I dusted off some old code and poked and prodded a little until it behaved somewhat as expected, there’s a functioning prototype on GitHub[2] with some basic instructions in the README.

As you probably guessed the algorithm is modified pre-order traversal, and the current working functionality is as follows

  • Store single trees or multiple trees in same table
  • Add, move & delete individual tree nodes or tree branches
  • operate on result set nodes(getPath(),getSiblings(),getDescendants(), etc )
  • Result-set as multi-dimensional associative array (Zend_Navigation)
  • Result-set as recursive iterator

Cheers the noo,
Graham

  1. http://framework.zend.com/wiki/display/ZFPROP/Zend_Db_NestedSet+-+Graham+Anderson
  2. http://github.com/gnanderson/ZF_NestedSet

2 Replies to “Proposal for Zend_Db_NestedSet – Hierarchical data as a nested set”

  1. Use Case #2 makes this a very interesting class;

    $table = new Zend_Db_NestedSet('categories'); 
    $tree = $table->getTree()->toMultiArray()  
    // or getTree($rootId) for mutli tree table 
    $navigation = new Zend_Navigation($tree); 
    

    Spice that with some ACL etc and you have a very nice way och NOT using XML files for the Zend_Navigation component 🙂

  2. I usually don’t post on Blogs but ya forced me to, great info.. excellent! … I’ll add a backlink and bookmark your site.

Leave a Reply

Your email address will not be published. Required fields are marked *