diff options
author | plegall <plg@piwigo.org> | 2016-01-28 16:03:39 +0100 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2016-01-28 16:03:39 +0100 |
commit | bc7316639f9208089ed3ab3debf313aca8ff986a (patch) | |
tree | 6a797402ca9ee66fee20599d0f1afdcdffe7ee1e /admin | |
parent | 417a6b77b2c996bb7739c636d44230117cd783d7 (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 'admin')
-rw-r--r-- | admin/element_set_ranks.php | 32 | ||||
-rw-r--r-- | admin/include/functions.php | 31 |
2 files changed, 30 insertions, 33 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); +} |