You are here

function user_relationships_load in User Relationships 5.2

Same name and namespace in other branches
  1. 5.3 user_relationships_api/user_relationships_api.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'}));

$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")

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

23 calls to user_relationships_load()
theme_user_relationship_block_pending in plugins/user_relationship_blocks/user_relationship_blocks.module
Generate the content for the pending block
theme_user_relationship_implications_page in plugins/user_relationship_implications/user_relationship_implications.module
Categorized list of relationships for a given user
user_relationships_direct_create_relationship_links in plugins/user_relationship_direct/user_relationship_direct.module
Make links to create all outstanding relationships to a user
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.

... See full list

File

./user_relationships_api.inc, line 225

Code

function user_relationships_load($param = array(), $count = FALSE, $sort = 'rid', $order = NULL, $limit = NULL, $include_user_info = FALSE, $reset = FALSE) {
  static $relationships = array();
  $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, $order, $limit, $include_user_info);
  $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 ($sort == 'rid') {
      $relationships[$relationship->{$sort}] = $relationship;
    }
    else {
      $relationships[$relationship->{$sort}][] = $relationship;
    }
  }
  return $rid ? $relationships[$rid] : $relationships;
}