You are here

function user_relationships_activity_access_grants in User Relationships 7

hook_activity_access_grants().

File

./user_relationships.activity.inc, line 24
provides the activity implementation for user_relationships module @todo: Port to D7 once activity.module is available. Maybe move to separate module.

Code

function user_relationships_activity_access_grants($account, $object = NULL, $type = NULL) {

  // load up all the users relationships
  $params = array(
    'user' => $account->uid,
  );
  $relationships = user_relationships_load($params);
  $relationship_ids = array();
  foreach ($relationships as $relationship) {

    // is this approved yet?
    $relationship_approved = !$relationship->requires_approval || $relationship->approved;
    if ($relationship_approved) {

      // if the relationship is not one way, grant to the other uid
      if (!$relationship->is_oneway) {
        if ($relationship->requester_id == $account->uid) {
          $relationship_ids["user_relationships_" . $relationship->rtid][] = $relationship->requestee_id;
        }
        else {
          $relationship_ids["user_relationships_" . $relationship->rtid][] = $relationship->requester_id;
        }
      }
      elseif ($relationship->is_oneway) {
        if ($relationship->requester_id == $account->uid) {
          $relationship_ids["user_relationships_" . $relationship->rtid][] = $relationship->requestee_id;
        }
      }
    }
  }
  return $relationship_ids;
}