Jelly-MPTT
Added by Alexander Kupreev almost 2 years ago
I tried to port Paul Banks' Sprig-MPTT for Jelly. I'm a Jelly newbie and think that my code is not optimal and is dirty, so any feedback especially bugs and bad codind style will be highly appreciated. To port correctly I used unit tests but this certainly can not guarantee absence of bugs.
Replies (9)
RE: Jelly-MPTT
-
Added by Sergei Gladkovskiy almost 2 years ago
Good job, Alexander!
I was scheduled to make mptt library for Jelly for the upcoming project, but you're way ahead of me... :)
I would propose to take off some of the methods out of the model, using the extending of the query builder to make your model code more jellyfied. :)
RE: Jelly-MPTT
-
Added by Alexander Kupreev almost 2 years ago
Thanks for reply, Sergei! I'll try to apply your advice as soon as possible. For me it was like a training but I'm going to look some real applications to try this code.
RE: Jelly-MPTT
-
Added by Paul Banks almost 2 years ago
Thanks for this Alexander.
We have eventual plans to include MPTT and other tree algorithms as behaviors in Jelly however judging by our current workload and amount of time we have available it could be some time so this port could be very useful.
Just thought I'd let you know the plans!
RE: Jelly-MPTT
-
Added by Alexander Kupreev over 1 year ago
Thanks for reply, Paul. Really I've read you mentioned about some 'native' MPTT implementation for Jelly, but I have little experience with Jelly extension yet and could not invent anything more intellectual. If you share some thoughts about how that should be done, maybe I'll try to do something.
RE: Jelly-MPTT
-
Added by Israel Canasa over 1 year ago
Wow this is what I've been waiting for. Even if the code base is not yet so clean, as long as it works, I'll use it. :) Thanks Alexander!
RE: Jelly-MPTT
-
Added by Michel Pierre over 1 year ago
Works perfectly. Thanks all for this.
I begin with MPTT and wondering how to retreive an array (for json encoding) in place of a list.
What would be the best (less consumption) recursion method to put in place or is there another way?
RE: Jelly-MPTT
-
Added by Michel Pierre over 1 year ago
Hello,
I don't know if this will support a big collection.
Some opinion ?
// retrieve all descendants of the $root node
$nodes = Jelly::select('collection', 1)->descendants(TRUE)->as_array();
$stack = array();
for($x =0; $x < count($nodes); $x++) {
$node = &$nodes[$x];
$node['children'] = array();
while(count($stack) > 0 && $stack[count($stack) - 1]['rgt'] < $node['rgt']) {
array_pop($stack);
}
if(count($stack) > 0) {
$stack[count($stack) - 1]['children'][] = &$node;
}
$stack[] = &$node;
}
return json_encode($stack[0]);
RE: Jelly-MPTT
-
Added by Paul Banks over 1 year ago
I don't know if this will support a big collection. Some opinion ?
I don't know how to answer. Firstly, what are you trying to do?
Secondly, what do you mean by 'support' and what do you mean by 'big'?
Anything that works with a small collection will work equally well with a big collection given enough RAM and processing time. Whether it is quick/efficient enough for your particular application on your server(s) we can't possibly comment on.
RE: Jelly-MPTT
-
Added by Michel Pierre over 1 year ago
I am sorry Paul. I don't receive email notification on the posts from this forum. Don't know why!
I will stress test MPTT/Jelly with a lot of different queries.
I keep in mind to come back with timing/processing results.
Thanks for your answer.
(1-9/9)