Closed (fixed)
Project:
User Relationship Locator
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
27 Mar 2012 at 16:27 UTC
Updated:
1 Jun 2012 at 23:21 UTC
Hi,
I am using User Relationship for a two-way relationship for a social network. This relationship is a two-way relationship: either user can initiate the relationship. In this case, the User RelationShip Locator needs to know about the 'people you know' when the other person initiated the relationship. Below is the code I currently use.
/**
* Helper function for looking up a given users relations
*/
function user_relationship_locator_graph_relations_lookup($currentuser, $iteration, $exclude = NULL){
//TODO: log performance here
$matches = array();
$relationship = variable_get('user_relationship_locator_relationship','');
$relationships = user_relationships_load(array('rtid' => $relationship, 'user' => $currentuser), array('include_twoway_reverse' => TRUE));
foreach ($relationships as $relationship) {
// Append both ways
$matches[$relationship->requestee_id] = $iteration;
$matches[$relationship->requester_id] = $iteration;
}
//exclude provided user
if(!empty($exclude)) {
unset($matches[$exclude]);
}
return $matches;
}
Please note that this also defers all lookups to the User Relationship module using the API, leaving caching etc. up to that module.
Comments
Comment #1
mrf commentedAdded this into the latest dev.