aboutsummaryrefslogtreecommitdiffstats
path: root/include/ws_functions
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2016-01-28 16:03:39 +0100
committerplegall <plg@piwigo.org>2016-01-28 16:03:39 +0100
commitbc7316639f9208089ed3ab3debf313aca8ff986a (patch)
tree6a797402ca9ee66fee20599d0f1afdcdffe7ee1e /include/ws_functions
parent417a6b77b2c996bb7739c636d44230117cd783d7 (diff)
fixes #349, API set ranks of all album photos at once
on pwg.images.setRank, ability to provide a list of image_id (and no rank). This way you can set the order of all photos of a given album, at once.
Diffstat (limited to 'include/ws_functions')
-rw-r--r--include/ws_functions/pwg.images.php35
1 files changed, 34 insertions, 1 deletions
diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php
index 1688c2130..1d9d0cbd4 100644
--- a/include/ws_functions/pwg.images.php
+++ b/include/ws_functions/pwg.images.php
@@ -740,7 +740,40 @@ UPDATE '. IMAGES_TABLE .'
* @option int rank
*/
function ws_images_setRank($params, $service)
-{
+{
+ if (count($params['image_id']) > 1)
+ {
+ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+
+ save_images_order(
+ $params['category_id'],
+ $params['image_id']
+ );
+
+ $query = '
+SELECT
+ image_id
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE category_id = '.$params['category_id'].'
+ ORDER BY rank ASC
+;';
+ $image_ids = query2array($query, null, 'image_id');
+
+ // return data for client
+ return array(
+ 'image_id' => $image_ids,
+ 'category_id' => $params['category_id'],
+ );
+ }
+
+ // turns image_id into a simple int instead of array
+ $params['image_id'] = array_shift($params['image_id']);
+
+ if (empty($params['rank']))
+ {
+ return new PwgError(WS_ERR_MISSING_PARAM, 'rank is missing');
+ }
+
// does the image really exist?
$query = '
SELECT COUNT(*)