mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-05-06 16:15:51 +03:00
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
This commit is contained in:
parent
6ba7f82306
commit
257808402b
3 changed files with 71 additions and 16 deletions
|
@ -533,4 +533,34 @@ SELECT image_id
|
||||||
|
|
||||||
return $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;
|
||||||
|
}
|
||||||
?>
|
?>
|
|
@ -432,6 +432,22 @@ function ws_categories_getList($params, &$service)
|
||||||
{
|
{
|
||||||
global $user,$conf;
|
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');
|
$where = array('1=1');
|
||||||
$join_type = 'INNER';
|
$join_type = 'INNER';
|
||||||
$join_user = $user['id'];
|
$join_user = $user['id'];
|
||||||
|
@ -471,7 +487,7 @@ function ws_categories_getList($params, &$service)
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = '
|
$query = '
|
||||||
SELECT id, name, permalink, uppercats, global_rank,
|
SELECT id, name, permalink, uppercats, global_rank, id_uppercat,
|
||||||
comment,
|
comment,
|
||||||
nb_images, count_images AS total_nb_images,
|
nb_images, count_images AS total_nb_images,
|
||||||
date_last, max_date_last, count_categories AS nb_categories
|
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);
|
array_push($cats, $row);
|
||||||
}
|
}
|
||||||
usort($cats, 'global_rank_compare');
|
usort($cats, 'global_rank_compare');
|
||||||
return array(
|
|
||||||
'categories' => new PwgNamedArray(
|
if ($params['tree_output'])
|
||||||
$cats,
|
{
|
||||||
'category',
|
return categories_flatlist_to_tree($cats);
|
||||||
array(
|
}
|
||||||
'id',
|
else
|
||||||
'url',
|
{
|
||||||
'nb_images',
|
return array(
|
||||||
'total_nb_images',
|
'categories' => new PwgNamedArray(
|
||||||
'nb_categories',
|
$cats,
|
||||||
'date_last',
|
'category',
|
||||||
'max_date_last',
|
array(
|
||||||
|
'id',
|
||||||
|
'url',
|
||||||
|
'nb_images',
|
||||||
|
'total_nb_images',
|
||||||
|
'nb_categories',
|
||||||
|
'date_last',
|
||||||
|
'max_date_last',
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
3
ws.php
3
ws.php
|
@ -81,8 +81,9 @@ function ws_addDefaultMethods( $arr )
|
||||||
'cat_id' => array('default'=>0),
|
'cat_id' => array('default'=>0),
|
||||||
'recursive' => array('default'=>false),
|
'recursive' => array('default'=>false),
|
||||||
'public' => array('default'=>false),
|
'public' => array('default'=>false),
|
||||||
|
'tree_output' => array('default'=>false),
|
||||||
),
|
),
|
||||||
'retrieves a list of categories' );
|
'retrieves a list of categories (tree_output option only compatible with json/php output format' );
|
||||||
|
|
||||||
$service->addMethod('pwg.images.addComment', 'ws_images_addComment',
|
$service->addMethod('pwg.images.addComment', 'ws_images_addComment',
|
||||||
array(
|
array(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue