Ignore:
Timestamp:
May 31, 2011, 10:25:40 PM (13 years ago)
Author:
plg
Message:

merge r11152 from branch 2.2 to trunk

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_category.inc.php

    r8802 r11155  
    534534  return $image_id;
    535535}
     536
     537/**
     538 * create a tree from a flat list of categories, no recursivity for high speed
     539 */
     540function categories_flatlist_to_tree($categories)
     541{
     542  $tree = array();
     543  $key_of_cat = array();
     544 
     545  foreach ($categories as $key => &$node)
     546  {
     547    $key_of_cat[$node['id']] = $key;
     548   
     549    if (!isset($node['id_uppercat']))
     550    {
     551      $tree[$key] = &$node;
     552    }
     553    else
     554    {
     555      if (!isset($categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories']))
     556      {
     557        $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'] = array();
     558      }
     559     
     560      $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'][$key] = &$node;
     561    }
     562  }
     563 
     564  return $tree;
     565}
    536566?>
Note: See TracChangeset for help on using the changeset viewer.