Pridan prototyp stromu kategorii pro budouci e-shop
authorThomas Mudrunka <tomas@mudrunka.cz>
Wed, 9 Nov 2011 16:45:23 +0000 (17:45 +0100)
committerThomas Mudrunka <tomas@mudrunka.cz>
Wed, 9 Nov 2011 16:45:23 +0000 (17:45 +0100)
assistants/category-tree.inc.php [new file with mode: 0644]

diff --git a/assistants/category-tree.inc.php b/assistants/category-tree.inc.php
new file mode 100644 (file)
index 0000000..f268ca7
--- /dev/null
@@ -0,0 +1,19 @@
+<pre><?php
+$result = $this->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);
This page took 0.168342 seconds and 4 git commands to generate.