You are here

function theme_user_relationships_page in User Relationships 5

Same name and namespace in other branches
  1. 5.3 user_relationships_ui/user_relationships_ui.theme.inc \theme_user_relationships_page()
  2. 5.2 user_relationships_theme.inc \theme_user_relationships_page()

Categorized list of relationships for a given user

File

./user_relationships_theme.inc, line 10

Code

function theme_user_relationships_page($uid = NULL, $relationship = NULL) {
  global $user;
  if (empty($uid) || $uid == $user->uid) {
    $viewed_user =& $user;
  }
  else {
    $viewed_user = user_load(array(
      'uid' => $uid,
    ));
  }

  // Check that the uid is valid, not the anonymous user, and the user exists
  if ($viewed_user->uid == 0) {
    drupal_not_found();
    exit;
  }
  $query = "SELECT r.*, rt.name, rt.plural_name, rt.is_oneway \n      FROM {user_relationships} r, {user_relationship_types} rt \n      WHERE (requester_id = %d OR requestee_id = %d) \n        AND r.rtid = rt.rtid \n        AND r.approved = 1";
  $args = array(
    $viewed_user->uid,
    $viewed_user->uid,
  );
  if (isset($relationship->rtid)) {
    $query .= " AND r.rtid = %d";
    $args[] = $relationship->rtid;
  }
  $relationships_per_page = variable_get('user_relationships_relationships_per_page', 16);
  $result = $relationships_per_page ? pager_query($query, $relationships_per_page, 0, NULL, $args) : db_query($query, $args);
  if (db_num_rows($result)) {
    $edit_access = $user->uid == $viewed_user->uid && user_access('maintain relationships') || user_access('administer users');
    $online_interval = time() - variable_get('user_block_seconds_online', 180);
    while ($relation = db_fetch_object($result)) {
      $this_user = $viewed_user->uid == $relation->requestee_id ? 'requester_id' : 'requestee_id';
      $this_user = user_load(array(
        'uid' => $relation->{$this_user},
      ));
      $rows[] = array(
        theme('username', $this_user),
        $relation->name,
        $this_user->access > $online_interval ? t('online') : t('not online'),
        $edit_access ? theme('user_relationships_remove_link', $viewed_user->uid, $relation) : ' ',
      );
    }
    $output .= theme('table', array(), $rows);
  }
  else {
    $output .= t('No relationships found');
  }
  $output .= theme('pager', NULL, $relationships_per_page);
  drupal_set_title(t("%username's %relationships", array(
    '%username' => $viewed_user->name,
    '%relationships' => $relationship->plural_name ? $relationship->plural_name : $relationship->name,
  )));
  return $output;
}