aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/ws_functions.inc.php72
-rw-r--r--ws.php12
2 files changed, 83 insertions, 1 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index e8767f45d..cc84460e2 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -2464,6 +2464,78 @@ function ws_categories_setInfo($params, &$service)
}
+function ws_categories_setRepresentative($params, &$service)
+{
+ global $conf;
+
+ if (!is_admin())
+ {
+ return new PwgError(401, 'Access denied');
+ }
+
+ if (!$service->isPost())
+ {
+ return new PwgError(405, "This method requires HTTP POST");
+ }
+
+ // category_id
+ // image_id
+
+ $params['category_id'] = (int)$params['category_id'];
+ if ($params['category_id'] <= 0)
+ {
+ return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
+ }
+
+ // does the category really exist?
+ $query='
+SELECT
+ *
+ FROM '.CATEGORIES_TABLE.'
+ WHERE id = '.$params['category_id'].'
+;';
+ $row = pwg_db_fetch_assoc(pwg_query($query));
+ if ($row == null)
+ {
+ return new PwgError(404, "category_id not found");
+ }
+
+ $params['image_id'] = (int)$params['image_id'];
+ if ($params['image_id'] <= 0)
+ {
+ return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
+ }
+
+ // does the image really exist?
+ $query='
+SELECT
+ *
+ FROM '.IMAGES_TABLE.'
+ WHERE id = '.$params['image_id'].'
+;';
+
+ $row = pwg_db_fetch_assoc(pwg_query($query));
+ if ($row == null)
+ {
+ return new PwgError(404, "image_id not found");
+ }
+
+ // apply change
+ $query = '
+UPDATE '.CATEGORIES_TABLE.'
+ SET representative_picture_id = '.$params['image_id'].'
+ WHERE id = '.$params['category_id'].'
+;';
+ pwg_query($query);
+
+ $query = '
+UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
+ SET user_representative_picture_id = NULL
+ WHERE cat_id = '.$params['category_id'].'
+;';
+ pwg_query($query);
+}
+
function ws_categories_delete($params, &$service)
{
global $conf;
diff --git a/ws.php b/ws.php
index e8bbb2590..3e666ee80 100644
--- a/ws.php
+++ b/ws.php
@@ -302,7 +302,17 @@ function ws_addDefaultMethods( $arr )
),
'Move categories. You can give several category_ids, comma separated. Set parent as 0 to move to gallery root. Only virtual categories can be moved.'
);
-
+
+ $service->addMethod(
+ 'pwg.categories.setRepresentative',
+ 'ws_categories_setRepresentative',
+ array(
+ 'category_id'=>array('default'=>0),
+ 'image_id'=>array('default'=>0),
+ ),
+ 'Set the representative photo for an album. The photo doesn\'t have to belong to the album. POST method only. Administration method only.'
+ );
+
$service->addMethod(
'pwg.tags.getAdminList',
'ws_tags_getAdminList',