You are here

function template_preprocess_user_relationships_block in User Relationships 7

Same name and namespace in other branches
  1. 6 user_relationship_blocks/user_relationship_blocks.module \template_preprocess_user_relationships_block()

Template pre processor for the main block view

File

user_relationship_blocks/user_relationship_blocks.module, line 348
User Relationship Blocks implementation @author Jeff Smick (creator) @author Alex Karshakevich (maintainer) http://drupal.org/user/183217

Code

function template_preprocess_user_relationships_block(&$variables) {
  $account =& $variables['account'];
  $settings =& $variables['settings'];
  $extra =& $variables['extra'];
  $query_opts = array(
    'include_user_info' => TRUE,
  );
  if (empty($settings->sort)) {
    $settings->sort = 'newest';
  }
  if (empty($settings->size)) {
    $settings->size = 10;
  }

  // select the appropriate set of relationships based on admin's configuration settings
  switch ($settings->sort) {
    case 'newest':
      $query_opts['order'] = array(
        'changed',
        'DESC',
      );
      break;
    case 'oldest':
      $query_opts['order'] = array(
        'changed',
        'ASC',
      );
      break;
    case 'random':
      $query_opts['order'] = 'RAND()';
      break;
  }
  $query_opts['limit'] = $settings->size;
  $key = $extra ? $extra == 'you_to_them' ? 'requester_id' : 'requestee_id' : 'user';
  $args = array(
    $key => $account->uid,
    'approved' => TRUE,
  );
  if ($settings->rtid != UR_BLOCK_ALL_TYPES) {
    $args['rtid'] = $settings->rtid;
  }
  $variables['relationships'] = user_relationships_load($args, $query_opts);
}