aboutsummaryrefslogtreecommitdiffstats
path: root/include/ws_functions.inc.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2011-05-31 20:25:40 +0000
committerplegall <plg@piwigo.org>2011-05-31 20:25:40 +0000
commit257808402bed53e44bc8705d22e4d05f99fc37da (patch)
tree64ae348853619567d2ea14c6df0d98ce71cfb3b1 /include/ws_functions.inc.php
parent6ba7f823069f08c98e9e40309021a3fb105775a2 (diff)
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. git-svn-id: http://piwigo.org/svn/trunk@11155 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/ws_functions.inc.php54
1 files changed, 39 insertions, 15 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 16d2f7dd4..98828fcb8 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -432,6 +432,22 @@ function ws_categories_getList($params, &$service)
{
global $user,$conf;
+ if ($params['tree_output'])
+ {
+ if (!isset($_GET['format']) or !in_array($_GET['format'], array('php', 'json')))
+ {
+ // the algorithm used to build a tree from a flat list of categories
+ // keeps original array keys, which is not compatible with
+ // PwgNamedArray.
+ //
+ // PwgNamedArray is useful to define which data is an attribute and
+ // which is an element in the XML output. The "hierarchy" output is
+ // only compatible with json/php output.
+
+ return new PwgError(405, "The tree_output option is only compatible with json/php output formats");
+ }
+ }
+
$where = array('1=1');
$join_type = 'INNER';
$join_user = $user['id'];
@@ -471,7 +487,7 @@ function ws_categories_getList($params, &$service)
}
$query = '
-SELECT id, name, permalink, uppercats, global_rank,
+SELECT id, name, permalink, uppercats, global_rank, id_uppercat,
comment,
nb_images, count_images AS total_nb_images,
date_last, max_date_last, count_categories AS nb_categories
@@ -514,21 +530,29 @@ SELECT id, name, permalink, uppercats, global_rank,
array_push($cats, $row);
}
usort($cats, 'global_rank_compare');
- return array(
- 'categories' => new PwgNamedArray(
- $cats,
- 'category',
- array(
- 'id',
- 'url',
- 'nb_images',
- 'total_nb_images',
- 'nb_categories',
- 'date_last',
- 'max_date_last',
+
+ if ($params['tree_output'])
+ {
+ return categories_flatlist_to_tree($cats);
+ }
+ else
+ {
+ return array(
+ 'categories' => new PwgNamedArray(
+ $cats,
+ 'category',
+ array(
+ 'id',
+ 'url',
+ 'nb_images',
+ 'total_nb_images',
+ 'nb_categories',
+ 'date_last',
+ 'max_date_last',
+ )
)
- )
- );
+ );
+ }
}
/**