You are here

function user_relationships_relationship_load in User Relationships 5

Public API for loading a relationship.

Parameters

$rid: integer relationship id

Return value

object of the requested relationship

4 calls to user_relationships_relationship_load()
user_relationships_pending_requested in ./user_relationships_forms.inc
Approve, Disapprove, or Cancel confirmation form
user_relationships_remove in ./user_relationships_forms.inc
Confirm relationship removal.
user_relationships_request_relationship in ./user_relationships_api.inc
Public API for creating a relationship.
user_relationship_implications_user_relationships in plugins/user_relationship_implications/user_relationship_implications.module
hook_user_relationships()

File

./user_relationships_api.inc, line 111

Code

function user_relationships_relationship_load($rid) {

  // we may have to do this more than once per page view. so cache it
  static $user_relationships = array();
  if (!$user_relationships[$rid]) {
    if (($cache = cache_get("user_relationships_relationship_{$rid}", 'cache_user_relationships')) && !empty($cache->data)) {
      $user_relationships[$rid] = unserialize($cache->data);
    }
    elseif ($relationship = db_fetch_object(db_query("SELECT * FROM {user_relationships} WHERE rid = %d", $rid))) {
      $relationship->requester = user_load(array(
        'uid' => $relationship->requester_id,
      ));
      $relationship->requestee = user_load(array(
        'uid' => $relationship->requestee_id,
      ));
      $relationship->type = user_relationships_relationship_type_load(array(
        'rtid' => $relationship->rtid,
      ));
      $relationship->name = $relationship->type->name;
      $relationship->plural_name = $relationship->type->plural_name;
      _user_relationships_invoke('load', $relationship);
      $user_relationships[$rid] = $relationship;
      cache_set("user_relationships_relationship_{$rid}", 'cache_user_relationships', serialize($relationship));
    }
  }
  return $user_relationships[$rid];
}