aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2011-07-14 21:44:14 +0000
committerplegall <plg@piwigo.org>2011-07-14 21:44:14 +0000
commit043166964297407540ed398c09e770d4f2f8b3b8 (patch)
treec2ae1313abd01968fed5893cf67a4f98d8161aa8 /include
parent02e22746344a95e035355b5e8a0255d34148bd92 (diff)
merge r11745 from branch 2.2 to trunk
feature 2376 added: new method pwg.categories.setRepresentative git-svn-id: http://piwigo.org/svn/trunk@11746 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/ws_functions.inc.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 40c7a38ef..b92814688 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -2467,6 +2467,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;