X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;ds=sidebyside;f=assistants%2Fcategory-tree.inc.php;fp=assistants%2Fcategory-tree.inc.php;h=f268ca774582abc8f482f49c5046ea40e885d608;hb=661e298830a700272104783b049367bf505bff62;hp=0000000000000000000000000000000000000000;hpb=0646d9ef395a35591e9539aaca5ec4d21aa7aa29;p=mirrors%2FSokoMan.git diff --git a/assistants/category-tree.inc.php b/assistants/category-tree.inc.php new file mode 100644 index 0000000..f268ca7 --- /dev/null +++ b/assistants/category-tree.inc.php @@ -0,0 +1,19 @@ +
db->safe_query_fetch('SELECT * FROM category'); + +function addleaf(&$tree, $levels, $category='') { + if(!count($levels)) return; + $current = array_shift($levels); + $category .= '/'.$current; + if(!isset($tree[$current])) $tree[$current] = array(); + $tree[$current]['__PATH__'] = $category; + addleaf($tree[$current], $levels, $category); +} + +$tree = array(); +foreach($result as $row) { + $row_parts = preg_split('/\//', $row['category_name']); + addleaf($tree, $row_parts); +} + +print_r($tree);