mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 19:59:56 +03:00
API call to add/remove favorites (#810)
add API methods pwg.users.addFavorite and pwg.users.removeFavorite
This commit is contained in:
parent
d406a12d45
commit
1d113c002b
2 changed files with 69 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue