You are here

function user_relationships_get_relationship_actions in User Relationships 5

File

./user_relationships.module, line 161

Code

function user_relationships_get_relationship_actions(&$viewing_user, &$viewed_user) {
  $actions = array();
  if (!user_access('maintain relationships') || !user_access('can have relationship', $viewing_user) || !user_access('can have relationship', $viewed_user) || $viewing_user->uid == $viewed_user->uid) {
    return $actions;
  }
  $relationships = user_relationships_get_relationships_for($viewing_user->uid, $viewed_user->uid);
  if (variable_get('user_relationships_require_approval', TRUE)) {
    $requests = user_relationships_get_requests($viewing_user->uid, $viewed_user->uid);
    $requestees = user_relationships_get_requestees($viewing_user->uid, $viewed_user->uid);
    if (sizeof($requests) > 0) {
      foreach ($requests as $relationship => $request) {
        $actions[] = t('You have requested to be a %relationship_name of this user. (See !your_pending_requests)', array(
          '%relationship_name' => $relationship,
          '!your_pending_requests' => l(t('your pending requests'), 'relationships/' . $viewing_user->uid . '/requests'),
        ));
      }
    }
    if (sizeof($requestees) > 0) {
      foreach ($requestees as $requestee) {
        $actions[] = t('This user believes that they are a %relationship_name of yours. (See !your_pending_requests)', array(
          '%relationship_name' => $requestee->name,
          '!your_pending_requests' => l(t('your pending requests'), 'relationships/' . $viewing_user->uid . '/requests'),
        ));
      }
    }
  }
  if (variable_get('user_relationships_allow_multiple', 1) || sizeof($relationships) == 0) {
    $count = db_result(db_query("SELECT COUNT(*) AS size FROM {user_relationship_types}"));
    if (sizeof($requests) + sizeof($relationships) < $count) {
      $actions[] = theme('user_relationships_request_relationship_link', $viewed_user);
    }
  }
  return $actions;
}