You are here

function user_relationships_load in User Relationships 6

Same name and namespace in other branches
  1. 5.3 user_relationships_api/user_relationships_api.api.inc \user_relationships_load()
  2. 5.2 user_relationships_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'}));

each parameter may be an array, if you wish to pass several values example: user_relationships_load(array('rtid' => array(2, 3), 'between' => array($uid1, $uid2))) will load all relationships of types 2 or 3 between uid1 and uid2 (query will have an IN clause)

@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 default is 'rid'

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

include_twoway_reverse (not used unless there is a specific need) a boolean that, if present, and if sort is set to other than 'rid', will include records for both directions for two-way relationships. Normally for a two-way relationship only one entry is returned, although in the database there are two records. This flag has no effect if sort is 'rid'

$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

31 calls to user_relationships_load()
rules_data_type_relationship::load in user_relationships_rules/user_relationships_rules.rules.inc
Loads the data identified with an identifier as returned by get_identifier(). Just return the data or FALSE if loading the data failed.
template_preprocess_user_relationships_block in user_relationship_blocks/user_relationship_blocks.module
Template pre processor for the main block view
template_preprocess_user_relationships_pending_block in user_relationship_blocks/user_relationship_blocks.module
Template pre processor for the pending relationships block
theme_user_relationship_implications_page in user_relationship_implications/user_relationship_implications.module
Categorized list of relationships for a given user
UserRelationshipsApiTestCase::testUserRelationshipsLoadDuplicates in user_relationships_api/tests/user_relationships_api.api.test

... See full list

File

user_relationships_api/user_relationships_api.api.inc, line 353
User Relationships API. Data abstraction layer @author Jeff Smick (creator) @author Alex Karshakevich (maintainer) http://drupal.org/user/183217

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[isset($count) && $count ? 'count' : 'query'], $query['arguments']);
  if (isset($count) && $count) {
    return (int) db_result($results);
  }
  $relationships = array();
  while ($relationship = db_fetch_object($results)) {
    if (isset($include_user_info)) {
      user_relationships_api_translate_user_info($relationship);
    }
    if ($sort == 'rid') {
      $relationships[$relationship->{$sort}] = $relationship;
    }
    else {
      $relationships[$relationship->{$sort}][] = $relationship;
    }
  }
  $return = isset($rid) ? $relationships[$rid] : $relationships;
  _user_relationships_invoke('load', $return);
  return $return;
}