You are here

function user_relationship_service_approve in User Relationships 6

Same name and namespace in other branches
  1. 5.2 plugins/user_relationship_service/user_relationship_service.module \user_relationship_service_approve()
  2. 7 user_relationship_service/user_relationship_service.inc \user_relationship_service_approve()
1 string reference to 'user_relationship_service_approve'
user_relationship_service_service in user_relationship_service/user_relationship_service.module
Implementation of hook_service().

File

user_relationship_service/user_relationship_service.inc, line 29
@author Drupal 6 port by Darren Ferguson <http://drupal.org/user/70179> @author Written by scottgifford http://drupal.org/user/245699 Link general user relationship functionalities to services module.

Code

function user_relationship_service_approve($version, $rid) {
  try {
    global $user;
    $rels = user_relationships_load(array(
      'rid' => $rid,
      'requestee_id' => $user->uid,
      'approved' => 0,
    ));
    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) {
      throw new Exception("Access denied");
    }
    user_relationships_save_relationship($rel, 'approve');
    return $rel;
  } catch (Exception $ex) {
    return services_error(t('Error approving relationship: @msg', array(
      '@msg' => $ex
        ->getMessage(),
    )));
  }
}