Traverzovani kolem stromu – generovanie addSelect s option group

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
duskohu
Člen | 778
+
0
-

Caute, Nerobili ste niekto selectBox s option group, z dat – traversovani okolo stromu?
Uz nejaky cas na tom sedim, ale podarilo sa mi len vygenerovat viacrozmerne pole Help, ktore bohuzial je nepouzitelne pre generovanie takehoto prvku. Nevie niekto pomoct?
Moja podoba je:

public function getTreeArray() {
    $data = $this->getTable();
    $data->order("left");

    $tree = array();
    foreach ($data as $value) {
        $tree[$value->id]['id'] = $value->id;
        $tree[$value->id]['parent_id'] = $value->parent_id;
        $tree[$value->id]['other'] = $value->toArray();
    }

    $menu = array();
    $ref = array();
    foreach ($tree as $d) {
        $d['children'] = array();
        if (isset($ref[$d['parent_id']])) { // we have a reference on its parent
            $ref[$d['parent_id']]['children'][$d['id']] = $d['other'];
            $ref[$d['id']] = & $ref[$d['parent_id']]['children'][$d['id']];
        } else { // we don't have a reference on its parent => put it a root level
            $menu[$d['id']] = $d;
            $ref[$d['id']] = & $menu[$d['id']];
        }
    }

    return $menu;
}

ale vystup neviem inak prerobit:

$output = array(
    id => 96,
    parent_id => 0,
    other => array(
        id => 96,
        name => "Kategória",
        depth => 0,
        left => 1,
        right => 60,
        parent_id => 0,
        children => array(
            168 => array(
                id => 168,
                name => "xxxx",
                depth => 1,
                left => 2,
                right => 9,
                parent_id => 96,
                children => array(),
            ),
        ),
    ),
);