From 8840ec3a53cac78e1179392447e70df9b4ea92c7 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Fri, 9 Dec 2011 21:40:51 +0100 Subject: [PATCH] Do stromu kategorii pridana IDcka --- assistants/category-tree.inc.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/assistants/category-tree.inc.php b/assistants/category-tree.inc.php index ce6c4c3..b41b547 100644 --- a/assistants/category-tree.inc.php +++ b/assistants/category-tree.inc.php @@ -1,26 +1,31 @@
db->safe_query_fetch('SELECT * FROM category');
 
-function addleaf(&$tree, $levels, $category='') {
-	if(!count($levels)) return;
-	$current = array_shift($levels);
+function addleaf(&$tree, $levels, $id, $category='') {
+	if(!count($levels)) {
+		$tree['__ID__'] = $id;
+		return;
+	}
+	$current = array_shift($levels); //echo("$current ".count($levels)."");
 	$category .= '/'.$current;
 	if(!isset($tree[$current])) $tree[$current] = array();
 	$tree[$current]['__PATH__'] = $category;
-	addleaf($tree[$current], $levels, $category);
+	//if(!count($levels)) $tree[$current]['__ID__'] = $id; //echo "($current $id)\n";
+	addleaf($tree[$current], $levels, $id, $category);
 }
 
 $tree = array();
 foreach($result as $row) {
 	$row_parts = preg_split('/\//', $row['category_name']);
-	addleaf($tree, $row_parts);
+	//echo($row['category_name'].$row['category_id']."\n");
+	addleaf($tree, $row_parts, $row['category_id']);
 }
 
-function render_tree($tree, $pathindex='__PATH__') {
+function render_tree($tree, $index_path='__PATH__', $index_id='__ID__') {
 	if(!is_array($tree)) return '';
 	$html='';
-		foreach($tree as $name => $subtree) if($name != $pathindex) {
-			$html.='
  • '.$name.' ('.$subtree[$pathindex].')'.render_tree($subtree).'
  • '; + foreach($tree as $name => $subtree) if($name != $index_path && $name != $index_id) { + @$html.='
  • '.$name.' ('.$subtree[$index_id].' => '.$subtree[$index_path].')'.render_tree($subtree).'
  • '; } $html.='
    '; return $html; -- 2.30.2