You are here

function theme_user_relationship_block_content in User Relationships 5.2

Generate the content of a non-empty My/User Relationships block

File

plugins/user_relationship_blocks/user_relationship_blocks.module, line 270

Code

function theme_user_relationship_block_content($viewing_user, $rtid, $relationships) {
  if (!$viewing_user) {
    return;
  }
  $rows = array();
  foreach ($relationships as $relationship) {
    if ($viewing_user->uid == $relationship->requester_id) {
      $extra = $relationship->is_oneway ? t(" (You to Them)") : NULL;
      $relatee = user_load(array(
        'uid' => $relationship->requestee_id,
      ));
    }
    else {
      $extra = $relationship->is_oneway ? t(" (Them to You)") : NULL;
      $relatee = user_load(array(
        'uid' => $relationship->requester_id,
      ));
    }
    $title = "{$relationship->plural_name}{$extra}";
    $user_picture = theme('user_picture', $relatee);
    $username = theme('username', $relatee);
    if (variable_get('user_relationships_show_user_pictures', FALSE)) {
      drupal_add_css(drupal_get_path('module', 'user_relationship_blocks') . '/user_relationship_blocks.css');

      // If we need to show pictures instead of user names, add a nested list
      // containing the picture and username.
      $display_relatee = array(
        'children' => array(
          $user_picture,
          $username,
        ),
        // Need to provide blank 'data' element, so theme_item_list resets its
        // internal $data variable, instead of adding onto the end of it.
        'data' => '',
      );
    }
    else {
      $display_relatee = $username;
    }
    if ($rtid == UR_BLOCK_ALL_TYPES) {
      $rows[$title]['data'] = $title;
      $rows[$title]['children'][] = $display_relatee;
    }
    else {
      $rows[$title][] = $display_relatee;
    }
  }
  foreach ($rows as $title => $users) {
    $output[] = theme('item_list', $rtid == UR_BLOCK_ALL_TYPES ? array(
      $users,
    ) : $users, NULL, 'ul', array(
      'class' => 'user_relationships_related',
    ));
  }
  return implode('', $output);
}