You are here

function template_preprocess_user_relationships in User Relationships 6

Pre processor for user_relationships page

File

user_relationships_ui/user_relationships_ui.module, line 816
UI components of user_relationships @author Jeff Smick (creator) @author Alex Karshakevich (maintainer) http://drupal.org/user/183217 @author Darren Ferguson (contributor) http://drupal.org/user/70179

Code

function template_preprocess_user_relationships(&$variables) {
  if (!empty($variables['rtid']) && !is_numeric($variables['rtid'])) {
    return NULL;
  }
  if (!empty($variables['account']) && !is_object($variables['account'])) {
    return NULL;
  }
  global $user;

  // readability
  $account = $variables['account'];
  $rtid = $variables['rtid'];
  $args = array(
    'user' => $account->uid,
    'approved' => TRUE,
  );
  if (isset($rtid) && is_numeric($rtid)) {
    $relationship_type = user_relationships_type_load($rtid);
    $args['rtid'] = $rtid;
  }
  $query = _user_relationships_generate_query($args, array(
    'include_user_info' => TRUE,
  ));

  // To Page or not to Page
  if ($variables['relationships_per_page'] = variable_get('user_relationships_relationships_per_page', 16)) {
    $results = pager_query($query['query'], $variables['relationships_per_page'], 0, $query['count'], $query['arguments']);
  }
  else {
    $results = db_query($query['query'], $query['arguments']);
  }
  $variables['relationships'] = array();
  while ($relationship = db_fetch_object($results)) {
    user_relationships_api_translate_user_info($relationship);
    $variables['relationships'][$relationship->rid] = $relationship;
  }
  if ($account->uid == $user->uid) {
    $msg = isset($relationship_type) ? t("My %relationships", array(
      '%relationships' => $relationship_type->plural_name ? ur_tt("user_relationships:rtid:{$relationship_type->rtid}:plural_name", $relationship_type->plural_name) : ur_tt("user_relationships:rtid:{$relationship_type->rtid}:name", $relationship_type->name),
    )) : t("All my relationships");
  }
  else {
    $msg = isset($relationship_type) ? t("%username's %relationships", array(
      '%username' => $account->name,
      '%relationships' => $relationship_type->plural_name ? ur_tt("user_relationships:rtid:{$relationship_type->rtid}:plural_name", $relationship_type->plural_name) : ur_tt("user_relationships:rtid:{$relationship_type->rtid}:name", $relationship_type->name),
    )) : t("All %username's relationships", array(
      '%username' => $account->name,
    ));
  }
  $variables['title'] = $msg;
}