You are here

function user_badges_for_user in User Badges 7

Same name and namespace in other branches
  1. 5 user_badges.module \user_badges_for_user()
  2. 6.2 user_badges.module \user_badges_for_user()
  3. 6 user_badges.module \user_badges_for_user()
  4. 7.2 user_badges.module \user_badges_for_user()
  5. 7.3 user_badges.module \user_badges_for_user()

Get all user badges for a user.

Parameters

$uid is user id.:

$list - boolean to return an item_list (unordered).:

Return value

string containing HTML representation of user badges for given user.

1 call to user_badges_for_user()
user_badges_preprocess_node in ./user_badges.module
Implements hook_preprocess_node().

File

./user_badges.module, line 1168
@brief User Badges module file

Code

function user_badges_for_user($uid, $list = FALSE) {
  static $save = array(
    0 => FALSE,
  );
  if (isset($save[$uid])) {
    return $save[$uid];
  }
  $account = user_load($uid);
  $badges = array();
  foreach ($account->badges as $badge) {
    $badges[] = theme('user_badge', array(
      'badge' => $badge,
      'account' => $account,
    ));
  }
  if ($list) {
    $badges = array(
      theme('item_list', array(
        'items' => $badges,
      )),
    );
    $save[$uid] = $badges;
    return $badges;
  }
  if ($badges) {
    $save[$uid] = theme('user_badge_group', array(
      'badgeimages' => $badges,
    ));
  }
  else {

    // Do we have a "no badges" message?
    if ($nobadges = variable_get('user_badges_nobadges', '')) {
      $nobadges = array(
        '<div class="user_badges_no_badges">' . filter_xss_admin(t($nobadges)) . '</div>',
      );
      $save[$uid] = theme('user_badge_group', array(
        'badgeimages' => $nobadges,
      ));
    }
    else {
      $save[$uid] = FALSE;
    }
  }
  return $save[$uid];
}