mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-05-09 09:57: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
|
* API method
|
||||||
* Returns the favorite images of the current user
|
* Returns the favorite images of the current user
|
||||||
|
|
20
ws.php
20
ws.php
|
@ -1077,6 +1077,26 @@ enabled_high, registration_date, registration_date_string, registration_date_sin
|
||||||
array('admin_only'=>true, 'post_only'=>true)
|
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(
|
$service->addMethod(
|
||||||
'pwg.users.getFavorites',
|
'pwg.users.getFavorites',
|
||||||
'ws_getFavorites',
|
'ws_getFavorites',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue