You are here

function theme_user_relationship_implications_page in User Relationships 7

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

Categorized list of relationships for a given user

File

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

Code

function theme_user_relationship_implications_page($variables) {
  global $user;
  $uid = $variables['uid'];
  $relationship = $variables['relation'];
  if (empty($uid)) {
    $viewed_user = $user;
  }
  else {
    $viewed_user = user_load($uid);
  }

  // Check that the uid is valid, not the anonymous user, and the user exists
  if ($viewed_user->uid == 0) {
    drupal_not_found();
    exit;
  }
  $params = array(
    'user' => $viewed_user->uid,
  );
  if (isset($relationship->rtid)) {
    $params['rtid'] = $relationship->rtid;
  }

  // To Page or not to Page.
  $variables['relationships_per_page'] = variable_get('user_relationships_relationships_per_page', 16);
  $options = array(
    'include_user_info' => TRUE,
    'paging' => $variables['relationships_per_page'],
  );
  $query = _user_relationships_generate_query($params, $options);
  $online_interval = time() - variable_get('user_block_seconds_online', 180);
  $rows = array();
  foreach ($query
    ->execute() as $relation) {
    $this_user = $viewed_user->uid == $relation->requestee_id ? 'requester_id' : 'requestee_id';
    $this_user = user_load($relation->{$this_user});
    $edit_access = user_relationships_ui_check_access('delete', NULL, $relation);
    $this_users_relationships = user_relationships_load(array(
      'user' => $this_user->uid,
    ));
    $rows[] = array(
      theme('username', array(
        'account' => $this_user,
      )),
      theme('item_list', array(
        'items' => _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', array(
        'uid' => $viewed_user->uid,
        'rid' => $relation->rid,
      )) : ' ',
    );
  }
  $output = '';
  if (count($rows)) {
    $output .= theme('table', array(
      'rows' => $rows,
      'attributes' => array(
        'class' => array(
          'user-relationship-implications-listing-table',
        ),
      ),
    ));
  }
  else {
    $output .= t('No relationships found');
  }
  $output .= theme('pager');
  drupal_set_title(t("%username's @rel_name_plural", array(
    '%username' => format_username($viewed_user),
  ) + user_relationships_type_translations($relationship)));
  return $output;
}