function user_relationship_service_delete in User Relationships 7
Same name and namespace in other branches
- 5.2 plugins/user_relationship_service/user_relationship_service.module \user_relationship_service_delete()
- 6 user_relationship_service/user_relationship_service.inc \user_relationship_service_delete()
Delete or cancel an relationship.
Parameters
$data: An object containing the relationship items. The $data object should contain: -rid (relationship id to delete or cancel. [GET] {endpoint}/relationships/ or @see user_relationships_load()) -reason (for deleting friendship. possible values: cancel, disapprove, remove)
Return value
The relationship object of the newly created relationship.
See also
user_relationships_delete_relationship()
1 string reference to 'user_relationship_service_delete'
- _user_relationship_service_definition in user_relationship_service/
user_relationship_service.module
File
- user_relationship_service/
user_relationship_service.inc, line 123 - Link general user relationship functionalities to services module.
Code
function user_relationship_service_delete($data) {
if (!$data['rid']) {
return services_error(t('Missing required field "rid".'), 404);
}
if (!$data['reason']) {
return services_error(t('Missing required field "reason".'), 404);
}
// Maintain compability with original code.
$rid = $data['rid'];
$reason = $data['reason'];
// Start of Darren Ferguson's code.
try {
global $user;
$rels = user_relationships_load(array(
'rid' => $rid,
'user' => $user->uid,
));
if (!$rels || !is_array($rels) || count($rels) != 1) {
throw new Exception("User relationship load failed");
}
$rel = array_shift($rels);
if ($rel->requestee_id != $user->uid && $rel->requester_id != $user->uid) {
throw new Exception("Access denied");
}
user_relationships_delete_relationship($rel, $user, $reason);
return $rel;
} catch (Exception $ex) {
return services_error(t('Error removing relationship: @msg', array(
'@msg' => $ex
->getMessage(),
)));
}
}