function user_relationships_block_select_relationships in User Relationships 5
function user_relationships_block_select_relationships given a $user object, select which of their relationships to display in the block
Parameters
$user - user object of user whose relationships we want to select:
$rtid - type id of relationships we're interested in, or 'ALL' for all relationships:
$how_many - how many relationships to return:
$options - array of (text) options presented to admins to allow them to select which n relationships to display:
$options_index - index into the $options array indicating which option the admin has selected for this type:
Return value
array of relationship objects
1 call to user_relationships_block_select_relationships()
File
- ./
user_relationships_actions.inc, line 243
Code
function user_relationships_block_select_relationships($user, $rtid, $how_many, $options, $options_index) {
// build the query and the argument list
$query = "SELECT * FROM {user_relationships} ";
$query .= " WHERE approved = 1 ";
$query .= " AND rtid = %d ";
$query .= " AND (requester_id = %d OR requestee_id = %d) ";
$args = array(
$rtid,
$user->uid,
$user->uid,
);
switch (drupal_strtolower($options[$options_index])) {
case 'newest':
$query .= "ORDER BY updated_at DESC ";
break;
case 'oldest':
$query .= "ORDER BY updated_at ";
break;
case 'random':
$query .= "ORDER BY RAND() ";
break;
}
$query .= "LIMIT {$how_many} ";
// build the array of relationships to return
$relationships = array();
$results = db_query($query, $args);
while ($relationship = db_fetch_object($results)) {
$relationships[] = $relationship;
}
return $relationships;
}