aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions_category.inc.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2011-05-31 20:21:08 +0000
committerplegall <plg@piwigo.org>2011-05-31 20:21:08 +0000
commit3197a76eda34281425764383aa2fda7a97bd2c8e (patch)
treea4abfd143e8a1eed32678a5b581745fa56927fab /include/functions_category.inc.php
parent214cc4de49bdfa2b5dcc799a89fa2009eae048a1 (diff)
feature 1622 added: pwg.categories.getList is now able to return a tree with
the new "tree_output" option. Only compatible with json/php output formats. git-svn-id: http://piwigo.org/svn/branches/2.2@11152 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/functions_category.inc.php')
-rw-r--r--include/functions_category.inc.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 8a0179418..44cefb0b5 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -533,4 +533,34 @@ SELECT image_id
return $image_id;
}
+
+/**
+ * create a tree from a flat list of categories, no recursivity for high speed
+ */
+function categories_flatlist_to_tree($categories)
+{
+ $tree = array();
+ $key_of_cat = array();
+
+ foreach ($categories as $key => &$node)
+ {
+ $key_of_cat[$node['id']] = $key;
+
+ if (!isset($node['id_uppercat']))
+ {
+ $tree[$key] = &$node;
+ }
+ else
+ {
+ if (!isset($categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories']))
+ {
+ $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'] = array();
+ }
+
+ $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'][$key] = &$node;
+ }
+ }
+
+ return $tree;
+}
?> \ No newline at end of file