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
This commit is contained in:
plegall
2011-05-31 20:21:08 +00:00
parent 214cc4de49
commit 3197a76eda
3 changed files with 71 additions and 16 deletions
+30
View File
@@ -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;
}
?>