You are here

function user_relationships_load_all_for_user in User Relationships 5

Public API for loading all the relationships for a specific user

Parameters

$uid: integer user id

Return value

array of relationships

5 calls to user_relationships_load_all_for_user()
theme_user_relationship_implications_page in plugins/user_relationship_implications/user_relationship_implications.module
Categorized list of relationships for a given user
_user_relationships_actions_between in ./user_relationships.module
List of pending relationships with between two users
_user_relationships_between in ./user_relationships.module
List of relationships between two users
_user_relationships_current_relationships in ./user_relationships.module
_user_relationships_set_notifications in ./user_relationships.module

File

./user_relationships_api.inc, line 74

Code

function user_relationships_load_all_for_user($uid, $reset = FALSE) {
  static $relationships = array();
  $cache_throttle = variable_get('user_relationships_cache_throttle', 5000);

  // max # of relationships to cache
  if ($reset || !key_exists($uid, $relationships)) {
    $relationships[$uid] = array();
    if (($cache = cache_get("user_relationships_relationships_{$uid}", 'cache_user_relationships')) && !empty($cache->data)) {
      $relationships[$uid] = unserialize($cache->data);
    }
    else {
      $results = db_query('SELECT r.*, rt.name, rt.plural_name, rt.is_oneway FROM {user_relationships} r, {user_relationship_types} rt
          WHERE (requester_id = %d OR requestee_id = %d)
            AND r.rtid = rt.rtid', $uid, $uid);
      while ($relationship = db_fetch_object($results)) {
        $relationships[$uid][] = $relationship;
      }
      if ($cache_throttle >= 0 && sizeof($relationships[$uid]) < $cache_throttle) {
        cache_set("user_relationships_relationships_{$uid}", 'cache_user_relationships', serialize($relationships[$uid]));
      }
    }
  }
  return $relationships[$uid];
}