Nested Set library (aka MPTT, aka Hierarchy DB Trees) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Nested Set library (aka MPTT, aka Hierarchy DB Trees) (/showthread.php?tid=11978) |
Nested Set library (aka MPTT, aka Hierarchy DB Trees) - El Forum - 09-30-2008 [eluser]Jon L[/eluser] Hey everyone. Last year I found Thunder's Nested Set class, implemented as a model. Thunder's original class was great, but there were a few things I felt were lacking. Thunder's Nested Set thread Some basic info before proceeding: - This class implements Joe Celko's Nested Set data model, also known as MPTT or Modified Preorder Tree Traversal. - Nested Sets are great for storing hierarchical data in a database. - This data model is a better alternative to the Adjacency List model. Changes: Quote:* Now implemented as a Library as opposed to Model (but could easily be converted back if needed) Attempts were made to keep this class compatible with Thunder's original class, and it is compatible in almost every way, EXCEPT for the following: Quote:- getRoot no longer exists, now getRootNodes is required, which returns an array of nodes The library is attached to this post. Example DB structure: Code: CREATE TABLE `nested_set_tree` ( Example basic PHP usage: Code: <?php I already have this class in use with Backend Pro. Had to modify Backend Pro of course, and also modified KHACL to use this class (as KHACL stores it's data using nested sets, but was managing the data itself, instead of using a dedicated class). Works great so far. Let me know if you have any questions/comments. Nested Set library (aka MPTT, aka Hierarchy DB Trees) - El Forum - 11-04-2008 [eluser]antonumia[/eluser] hello, Have you updated this for 1.6/7? anton Nested Set library (aka MPTT, aka Hierarchy DB Trees) - El Forum - 11-10-2008 [eluser]tobben[/eluser] There is a error at line 605: Code: public function getTreeNext($tree_handle) { should be: Code: public function getTreeNext(&$tree_handle) { ...anyways, its seems to work well under 1.6/1.7. There could probably be made some improvements. Additional helpers/methods.: - Rendering out ol/ul of entire tree and/or sub-tree. - Rendering out other types of important navigation elements, with easy steps. Ex. bredcrumbs etc. Nested Set library (aka MPTT, aka Hierarchy DB Trees) - El Forum - 11-10-2008 [eluser]tobben[/eluser] Though.. the AR-statements should be updated, since some of them are deprecated. Nested Set library (aka MPTT, aka Hierarchy DB Trees) - El Forum - 11-10-2008 [eluser]tobben[/eluser] There is also an error in function/method getSubTreeAsHTML, somewhere around line 691. Code: if(isset($nodes[0]) && !is_array($nodes[0])) { Should be: Code: if(isset($nodes[0]) && !is_array($nodes[0])) { Nested Set library (aka MPTT, aka Hierarchy DB Trees) - El Forum - 11-10-2008 [eluser]tobben[/eluser] Actually.. here is quite a few errors, If im not mistaken. Nested Set library (aka MPTT, aka Hierarchy DB Trees) - El Forum - 02-10-2009 [eluser]asylmottaket[/eluser] Hi. I think this seems promising (as well as CodeIgniter itself). (Also thanks to Thunder for the first contribution) I have one issue though: how to generate a valid unordered list/navigation menu. It's probably similar to this: Code: public function getSubTreeAsHTML($nodes, $fields = array()) { But other than that, I'm confused, so I would really appreciate any help! Thanks, Asylmottaket Nested Set library (aka MPTT, aka Hierarchy DB Trees) - El Forum - 02-13-2009 [eluser]Jon L[/eluser] I'm working with this class outside of CI, and I'm cleaning up any issues I find as I go along. I'll be posting back an updated version in a week or so. Cheers Nested Set library (aka MPTT, aka Hierarchy DB Trees) - El Forum - 06-26-2009 [eluser]tmkajk[/eluser] Hello Jon, I was wondering if you had made any additional progress with this? Regards, Todd M. Kimball Nested Set library (aka MPTT, aka Hierarchy DB Trees) - El Forum - 10-02-2009 [eluser]dirkpostma[/eluser] Why did you convert it to a library? I think a model is much easier, or not? I mean, if I create a model for nested categories, Code: class Cat extends Model Code: class Cat extends Nested_Set |