6

I have a following situation. I have a Model A with following properties: id int name varchar(255) parent_id int (references same Model A).

Now, I need to render Tree View using that ModelA. Of course, I could just load all data, sort it properly by parent_id and "render it" using traditional string sticking. e.g.

class Model_A extends Model_Table {
...

function render_branch($nodes, $parent){
    if (!isset($nodes[$parent])){
        return null;
    }
    $out = "<ul>";
    foreach ($nodes[$parent] as $node){
        $out .= "<li>" . $node["name"];
        $out .= $this->render_branch($nodes, $node["id"]);
        $out .= "</li>";
    }
    return $out;
}

function init(){
    parent::init();
    $nodes = array(); // preload from db and arrange so that key = parent and content is array of childs
    $this->template->set("tree", $this->render_branch($nodes, 0));
}

}

now, I would instead like to use atk4 native lister/smlite template parser for the purpose. but, if you try to do that, then you would end up with nasty lister, where in format row, you would anyway try to substitute the specific tag with output from other lister which in fact you would have to destruct to void runtime memory overflows.

any suggestions?

p.s. code above is not tested, just shows concept

thanks!

CAM
  • 185
  • 13
jancha
  • 4,916
  • 1
  • 24
  • 39
  • okay, after spending some time about possible options, I found that easier in this particular case was to use above mentioned example. only way to make it more native would be to use external template for nodes and use smite and clone region + render to move html outside t o template. apart from that, usage of traditional lister did not seem to be efficient enough. so, atk4 guys, follow up with query tree view plugin and create proper backend! it would be cool. thanks,j. – jancha Aug 31 '11 at 21:52
  • 1
    Please add you solution as an answer below and accept it. This will mark your question as solved. Thank you! – hakre Oct 27 '11 at 22:35
  • I won't accept what I have above, because it is not a solution. When there is a proper integrated solution, I will update this question with proper update. So far, it can be assumed that there is no built-in solution for the problem. – jancha Apr 23 '12 at 11:53
  • Fair point, if you keep it updated form time to time ;) – hakre Apr 23 '12 at 12:52

2 Answers2

3

Okay, right time had come and proper add-on has been created. To use it, get your add ons and atk4 up-to-dated and follow this article to get to know how.

http://www.ambienttech.lv/blog/2012-07-06/tree_view_in_agile_toolkit.html

jancha
  • 4,916
  • 1
  • 24
  • 39
0

As per Jancha's comment

okay, after spending some time looking at possible options, I found that the easiest thing to do in this particular case was to use above mentioned example. The only way to make it more native would be to use external template for nodes and use smite and clone region + render to move html outside t o template. apart from that, usage of traditional lister did not seem to be efficient enough. so, atk4 guys, follow up with query tree view plugin and create proper backend! it would be cool. thanks,j

.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124