Ignore:
Timestamp:
May 31, 2011, 10:21:08 PM (10 years ago)
Author:
plg
Message:

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
  • branches/2.2/include/ws_functions.inc.php

    r11117 r11152  
    433433  global $user,$conf;
    434434
     435  if ($params['tree_output'])
     436  {
     437    if (!isset($_GET['format']) or !in_array($_GET['format'], array('php', 'json')))
     438    {
     439      // the algorithm used to build a tree from a flat list of categories
     440      // keeps original array keys, which is not compatible with
     441      // PwgNamedArray.
     442      //
     443      // PwgNamedArray is useful to define which data is an attribute and
     444      // which is an element in the XML output. The "hierarchy" output is
     445      // only compatible with json/php output.
     446     
     447      return new PwgError(405, "The tree_output option is only compatible with json/php output formats");
     448    }
     449  }
     450
    435451  $where = array('1=1');
    436452  $join_type = 'INNER';
     
    472488
    473489  $query = '
    474 SELECT id, name, permalink, uppercats, global_rank,
     490SELECT id, name, permalink, uppercats, global_rank, id_uppercat,
    475491    comment,
    476492    nb_images, count_images AS total_nb_images,
     
    515531  }
    516532  usort($cats, 'global_rank_compare');
    517   return array(
    518     'categories' => new PwgNamedArray(
    519       $cats,
    520       'category',
    521       array(
    522         'id',
    523         'url',
    524         'nb_images',
    525         'total_nb_images',
    526         'nb_categories',
    527         'date_last',
    528         'max_date_last',
     533
     534  if ($params['tree_output'])
     535  {
     536    return categories_flatlist_to_tree($cats);
     537  }
     538  else
     539  {
     540    return array(
     541      'categories' => new PwgNamedArray(
     542        $cats,
     543        'category',
     544        array(
     545          'id',
     546          'url',
     547          'nb_images',
     548          'total_nb_images',
     549          'nb_categories',
     550          'date_last',
     551          'max_date_last',
     552          )
    529553        )
    530       )
    531     );
     554      );
     555  }
    532556}
    533557
Note: See TracChangeset for help on using the changeset viewer.