aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/element_set_ranks.php32
-rw-r--r--admin/include/functions.php31
-rw-r--r--include/ws_functions/pwg.images.php35
-rw-r--r--ws.php13
4 files changed, 73 insertions, 38 deletions
diff --git a/admin/element_set_ranks.php b/admin/element_set_ranks.php
index 2181dbed3..7ff57faee 100644
--- a/admin/element_set_ranks.php
+++ b/admin/element_set_ranks.php
@@ -46,38 +46,6 @@ if (!isset($_GET['cat_id']) or !is_numeric($_GET['cat_id']))
$page['category_id'] = $_GET['cat_id'];
// +-----------------------------------------------------------------------+
-// | functions |
-// +-----------------------------------------------------------------------+
-
-/**
- * save the rank depending on given images order
- *
- * The list of ordered images id is supposed to be in the same parent
- * category
- *
- * @param array categories
- * @return void
- */
-function save_images_order($category_id, $images)
-{
- $current_rank = 0;
- $datas = array();
- foreach ($images as $id)
- {
- $datas[] = array(
- 'category_id' => $category_id,
- 'image_id' => $id,
- 'rank' => ++$current_rank,
- );
- }
- $fields = array(
- 'primary' => array('image_id', 'category_id'),
- 'update' => array('rank')
- );
- mass_updates(IMAGE_CATEGORY_TABLE, $fields, $datas);
-}
-
-// +-----------------------------------------------------------------------+
// | global mode form submission |
// +-----------------------------------------------------------------------+
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 69ecb0032..4d3ccebe6 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -2848,4 +2848,33 @@ SELECT
;';
return query2array($query, null, 'id');
-} \ No newline at end of file
+}
+
+/**
+ * save the rank depending on given images order
+ *
+ * The list of ordered images id is supposed to be in the same parent
+ * category
+ *
+ * @param int category_id
+ * @param int[] images
+ * @return void
+ */
+function save_images_order($category_id, $images)
+{
+ $current_rank = 0;
+ $datas = array();
+ foreach ($images as $id)
+ {
+ $datas[] = array(
+ 'category_id' => $category_id,
+ 'image_id' => $id,
+ 'rank' => ++$current_rank,
+ );
+ }
+ $fields = array(
+ 'primary' => array('image_id', 'category_id'),
+ 'update' => array('rank')
+ );
+ mass_updates(IMAGE_CATEGORY_TABLE, $fields, $datas);
+}
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(*)
diff --git a/ws.php b/ws.php
index 25066b0d8..66e6a707d 100644
--- a/ws.php
+++ b/ws.php
@@ -293,11 +293,16 @@ function ws_addDefaultMethods( $arr )
'pwg.images.setRank',
'ws_images_setRank',
array(
- 'image_id' => array('type'=>WS_TYPE_ID),
+ 'image_id' => array('type'=>WS_TYPE_ID,'flags'=>WS_PARAM_FORCE_ARRAY),
'category_id' => array('type'=>WS_TYPE_ID),
- 'rank' => array('type'=>WS_TYPE_INT|WS_TYPE_POSITIVE|WS_TYPE_NOTNULL)
- ),
- 'Sets the rank of a photo for a given album.',
+ 'rank' => array('type'=>WS_TYPE_INT|WS_TYPE_POSITIVE|WS_TYPE_NOTNULL, 'default'=>null)
+ ),
+ 'Sets the rank of a photo for a given album.
+<br><br>If you provide a list for image_id:
+<ul>
+<li>rank becomes useless, only the order of the image_id list matters</li>
+<li>you are supposed to provide the list of all image_ids belonging to the album.
+</ul>',
$ws_functions_root . 'pwg.images.php',
array('admin_only'=>true, 'post_only'=>true)
);