static function getCategoryTree($db, $selected_id = null) { if (isset(Category::$cache_tree)) { $tree_root = Category::$cache_tree; } else { $all = Category::select($db, 'viewCategories', null, null, null, null, 'category_name'); $tree_root = new Category(); $tree_root->data['category_name'] = 'MENU'; $tree_root->is_on_selected_path = true; while (count($all) > 0) { foreach ($all as $i => $c) { $parent = null; if ($c->ival('category_parent_id') == null) { $parent = $tree_root; } else { $parent = $tree_root->findInChildren($c->ival('category_parent_id')); } if (isset($parent)) { $parent->addChild($c); unset($all[$i]); } } } Category::$cache_tree = $tree_root; } if (isset($selected_id)) { $sc = $tree_root->findInChildren($selected_id); $sc->is_selected = true; $sc->setSelectedPath(); } return $tree_root; }