You are here

function user_relationships_load in User Relationships 5.3

Same name and namespace in other branches
  1. 5.2 user_relationships_api.inc \user_relationships_load()
  2. 6 user_relationships_api/user_relationships_api.api.inc \user_relationships_load()
  3. 7 user_relationships.module \user_relationships_load()

Load relationship objects from the database.

Parameters

$param: an array of parameters with the key being the column. columns from both the user_relationships and user_relationship_types tables will work columns from user_relationships: rid, requester_id, requestee_id, rtid, approved, created_at, updated_at, flags columns from user_relationship_types: name, plural_name, is_oneway, requires_approval, expires_val There are two special keys: 1) array("between" => array($uid1, $uid2)) will return all relationships between the two user ids. 2) array("user" => $uid) will return all relationships for the specified uid

arguments will process operators as well using the syntax: array(col => '> {value}'). example: show all relationships created in 2007 $start_time = mktime(0,0,0,0,0,2007); $end_time = mktime(0,0,0,0,0,2008); user_relationships_load(array('created_at' => ">= {$start_time}", 'created_at' => '< {$end_time'}));

@options: An array keyed by the option count a boolean stating whether or not the return value should be the number of relationships found

sort a string containing a valid column name which will become the key for the returned array of relationships

order a string containing SQL stating the column and direction of the sort (ex. "requester_id ASC, rtid DESC")

limit a string containing SQL stating the limit (ex "10" or "10, 5")

include_user_info a boolean that will load basic user info without having to call user_load columns: uid, name, mail, data, picture

$reset: a boolean that will reset the internal static $relationships variable to ensure programatic relationship insertion works

Return value

an array of relationships if the key is "rid" the array will be a single dimention: array($rid => $relationship, $rid => $relationship) otherwise it'll be multidimentional: array($rtid => array($relationship, $relationship))

each relationship will have the user's name, mail, and data attached as requester_name, requester_mail, requester_data or requestee_name, requestee_mail, requestee_data

11 calls to user_relationships_load()
user_relationships_request_relationship in user_relationships_api/user_relationships_api.api.inc
Public API for creating a relationship.
user_relationships_ui_pending_requested in user_relationships_ui/user_relationships_ui.forms.inc
Approve, Disapprove, or Cancel confirmation form
user_relationships_ui_pending_requested_submit in user_relationships_ui/user_relationships_ui.actions.inc
Approve, Disapprove, or Cancel a relationship request
user_relationships_ui_remove in user_relationships_ui/user_relationships_ui.forms.inc
Confirm relationship removal.
user_relationships_ui_remove_submit in user_relationships_ui/user_relationships_ui.actions.inc
Remove a relationship

... See full list

File

user_relationships_api/user_relationships_api.api.inc, line 327

Code

function user_relationships_load($param = array(), $options = array(), $reset = FALSE) {
  static $relationships = array();
  $default_options = array(
    'sort' => 'rid',
  );
  $options = array_merge($default_options, $options);
  extract($options, EXTR_SKIP);
  $arguments = array();
  if (is_numeric($param)) {
    if (!$reset && isset($relationships[$param])) {
      return is_object($relationships[$param]) ? drupal_clone($relationships[$param]) : $relationships[$param];
    }
    $rid = $param;
    $param = array(
      'rid' => $param,
    );
  }
  $query = _user_relationships_generate_query($param, $options);
  $results = db_query($query[$count ? 'count' : 'query'], $query['arguments']);
  if ($count) {
    return (int) db_result($results);
  }
  $relationships = array();
  while ($relationship = db_fetch_object($results)) {
    if ($include_user_info) {
      user_relationships_api_translate_user_info($relationship);
    }
    if ($sort == 'rid') {
      $relationships[$relationship->{$sort}] = $relationship;
    }
    else {
      $relationships[$relationship->{$sort}][] = $relationship;
    }
  }
  $return = $rid ? $relationships[$rid] : $relationships;
  _user_relationships_invoke('load', $return);
  return $return;
}