You are here

function theme_user_relationship_implications_page in User Relationships 5

Same name and namespace in other branches
  1. 5.2 plugins/user_relationship_implications/user_relationship_implications.module \theme_user_relationship_implications_page()
  2. 6 user_relationship_implications/user_relationship_implications.module \theme_user_relationship_implications_page()
  3. 7 user_relationship_implications/user_relationship_implications.module \theme_user_relationship_implications_page()

Categorized list of relationships for a given user

File

plugins/user_relationship_implications/user_relationship_implications.module, line 271
Drupal Module: User Relationship Implications

Code

function theme_user_relationship_implications_page($uid = NULL, $relationship = NULL) {
  global $user;
  if (empty($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.is_oneway \n      FROM {user_relationships} r, {user_relationship_types} rt\n      WHERE (requester_id = %d OR requestee_id = %d)\n        AND r.approved = 1\n        AND r.rtid = rt.rtid";
  $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 == $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},
      ));
      $relations = array();
      $this_users_relationships = user_relationships_load_all_for_user($this_user->uid);
      $rows[] = array(
        theme('username', $this_user),
        theme('item_list', _user_relationship_implications_load_relationship_names($this_users_relationships, $viewed_user->uid)),
        $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 : t('relationships'),
  )));
  return $output;
}