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

mrf’s picture

Status: Active » Fixed

Added this into the latest dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.