MPTtree, Hieararchical trees in a database table |
[eluser]m4rw3r[/eluser]
Ok, seems like it's complaining on the debug_message() function. Remove the ampersand in the definition of debug_message(): function debug_message(&$message){ to function debug_message($message){ The default settings are covered in the manual.
[eluser]MaxPar[/eluser]
Wow, talk about a fast response! Now the error has changed to: Quote:A PHP Error was encountered Do you think this could have anything to do with my version of MySQL? Also, I neglected to mention in my previous post that I'm running the latest version of CodeIgniter.
[eluser]MaxPar[/eluser]
I deleted and re-entered the database in MySQL, and now it seems to be working fine. I guess I must have typod something as I was entering it :\ :\ Anyway, thanks so much for your (extremely fast!) help and work on this code. This is a really great plugin!
[eluser]TheLoops[/eluser]
After installing MPTree in an application that uses Matchbox I get this conflict with Matchbox: Quote:A PHP Error was encounteredIt would be great if this could be fixed. Matchbox uses a library called "Loader.php" that replaces CI's native CI_Loader with an enhanced one. It looks like there is a loading conflict with the loading order between MPTree and Matchbox. I tried the following fix (rather a dirty hack): I cut the class from MY_Loader.php and pasted it into Matchbox's Loader.php right after the CI_Loader class declaration. Then I deleted MY_Loader.php. Works like a charme. But way too dirty to keep it that way, imho.
[eluser]TheLoops[/eluser]
I myself have have written (or rather adapted) a nested tree model for CI. I actually just turned this class to a CI model that uses CI's native Active Record. But unfortunately it does not have any useful editing functionality implemented. Hence I'll most likely have to drop it in favor of MPTree. Nevertheless there are some features in my model wich I'd like to see in MPTree. Quote:(bool) isDescendantOf(…) Furthermore I'm curious why you did not add a parent_id and a nlevel field to MPTree. Using such fields would make many of MPTree's so more simple. Both: to understand for the user and also to maintenance. Just take thes simple query as example: MPTree's approach WITHOUT a parent_id field: Code: function count_children($lft,$rgt){ Versus an approach WITH a parent_id field: Code: function count_children($lft,$rgt,$id = NULL){ Or another MPTree's approach WITHOUT a parent_id field: Code: function AR_from_children_of($lft,$rgt){ Versus an approach with parent_id field: Code: function AR_from_children_of($lft,$rgt,$id = NULL){ I highly recommend to use a parent_id field. It just makes things much easier. And the MySQL queries should also get a significant performance boost in some cases.
[eluser]TheLoops[/eluser]
And now why to add an nlevel field: Just compare these functions for getting "A node's descendants for up to 3 levels in depth": A MPTree-like approach WITHOUT an nlevel field: Code: function get_descendants_within_depth($lft,$rgt,$dpth){ Versus an approach WITH an nlevel field: Code: function get_descendants_within_depth($lft,$rgt,$dpth){
[eluser]m4rw3r[/eluser]
How about get_parents()? And xpath()? And descendants()? move and delete? There are a lot of recursive queries there. Everything involving more than two levels next to each other would be more complicated. Plus you loose the order of the nodes and you store the same data in two places. Some queries would be faster, but others would be a lot slower (ex. traversing the tree). I could make a convert2adjacency_list() method, and another which does the opposite. And I'll look at those you painted in red, but I can't promise all of them. (I'll also look at that with matchbox). Thanks for the feedback!
[eluser]TheLoops[/eluser]
[quote author="m4rw3r" date="1211004097"]How about get_parents()? And xpath()? And descendants()? move and delete?[/quote] Well, you're right parent_id doesn't help everywhere. But I did not ask you to get rid of nleft and nright. I just asked you to add an additional parent_id and nlevel field to optimize certain sql queries that would be way too complex without it, imho. get_parents() cannot get improved from how it is right now. Same for descendants(). Just keep them the way they are. And for move & delete: Move -> parent_id would only need to be updated once a node leaves its current parent. (nlevel would even stay the same until the node changes its parent AND level) Delete -> the node just vanishes, so no need to update its parent_id or nlevel at all. [quote author="m4rw3r" date="1211004097"] There are a lot of recursive queries there. Everything involving more than two levels next to each other would be more complicated. Plus you loose the order of the nodes and you store the same data in two places. Some queries would be faster, but others would be a lot slower (ex. traversing the tree).[/quote]Well, as I said, take parent_id and nlevel as additional fields. Wherever parent_id or nlevel is of no help, the functions just stay the way they are right now. ;-) And having duplicate ID data in an additional field might be a (pretty damn small) overhead in case of memory, but it's definitely worth it, I think. [quote author="m4rw3r" date="1211004097"]I could make a convert2adjacency_list() method, and another which does the opposite.[/quote]Not sure what you mean. ![]() [quote author="m4rw3r" date="1211004097"]And I'll look at those you painted in red, but I can't promise all of them. (I'll also look at that with matchbox).[/quote]Thanks. ![]()
[eluser]m4rw3r[/eluser]
I could try to implement a hybrid of Modified Preorder Tree Traversal (lft and rgt) and Adjacency List (parent_id and level) (I will probably add it as an option to MPTtree). About the getDescendantsCounts() and getChildrenCount(), should they really return an int? I believe you can use count_descendants() / count_children() otherwise, if you only need an int in return. And the is_descendant_of() and is_child_of() I'll probably implement in the ORM, it seems more fitting there. Haven't checked this with matchbox, haven't really used matchbox before, but I'll look into it (got some work with school, so it may take some time before I have time to do anything of those above).
[eluser]TheLoops[/eluser]
[quote author="m4rw3r" date="1211041197"]I could try to implement a hybrid of Modified Preorder Tree Traversal (lft and rgt) and Adjacency List (parent_id and level) (I will probably add it as an option to MPTtree).[/quote]That would be great. (else I'd have to hack it in myelf ;-P ) [quote author="m4rw3r" date="1211041197"]About the getDescendantsCounts() and getChildrenCount(), should they really return an int? I believe you can use count_descendants() / count_children() otherwise, if you only need an int in return.[/quote]Well, the benefit of this method is that you do not need to run an sql query for each and every node. And having a descendants-count at hand is very handy in many situations. [quote author="m4rw3r" date="1211041197"]And the is_descendant_of() and is_child_of() I'll probably implement in the ORM, it seems more fitting there.[/quote]Right. [quote author="m4rw3r" date="1211041197"]Haven't checked this with matchbox, haven't really used matchbox before, but I'll look into it (got some work with school, so it may take some time before I have time to do anything of those above).[/quote]Matchbox replaces (replacing, no subclassing!) the CI_Loader with its own enhanced class. And this crashes MPTree. Dunno why, though. |
Welcome Guest, Not a member yet? Register Sign In |