diff --git a/include/ws_functions/pwg.users.php b/include/ws_functions/pwg.users.php index fb9fa009a..e8346ccf6 100644 --- a/include/ws_functions/pwg.users.php +++ b/include/ws_functions/pwg.users.php @@ -632,6 +632,55 @@ SELECT )); } +/** + * API method + * Adds a favorite image for the current user + * @param mixed[] $params + */ +function ws_addFavorite($params, &$service) +{ + global $user; + if (is_a_guest()) + { + return new PwgError(403, 'User must be logged in.'); + } + + $query = ' +INSERT IGNORE INTO '.FAVORITES_TABLE.' + (image_id,user_id) + VALUES + ('.$params['image_id'].','.$user['id'].') +;'; + + pwg_query($query); + + return true; +} + +/** + * API method + * Removes a favorite image for the current user + * @param mixed[] $params + */ +function ws_removeFavorite($params, &$service) +{ + global $user; + if (is_a_guest()) + { + return new PwgError(403, 'User must be logged in.'); + } + + $query = ' +DELETE FROM '.FAVORITES_TABLE.' + WHERE user_id = '.$user['id'].' + AND image_id = '.$params['image_id'].' +;'; + + pwg_query($query); + + return true; +} + /** * API method * Returns the favorite images of the current user diff --git a/ws.php b/ws.php index 241d78397..bbd4c4a5c 100644 --- a/ws.php +++ b/ws.php @@ -1077,6 +1077,26 @@ enabled_high, registration_date, registration_date_string, registration_date_sin array('admin_only'=>true, 'post_only'=>true) ); + $service->addMethod( + 'pwg.users.addFavorite', + 'ws_addFavorite', + array( + 'image_id' => array('type'=>WS_TYPE_ID) + ), + 'Adds the indicated image to the current user\'s favorite images.', + $ws_functions_root . 'pwg.users.php' + ); + + $service->addMethod( + 'pwg.users.removeFavorite', + 'ws_removeFavorite', + array( + 'image_id' => array('type'=>WS_TYPE_ID) + ), + 'Removes the indicated image from the current user\'s favorite images.', + $ws_functions_root . 'pwg.users.php' + ); + $service->addMethod( 'pwg.users.getFavorites', 'ws_getFavorites',