You are here

function user_badges_for_uid in User Badges 7.2

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

Returns HTML representation of user badges for given uid

Parameters

$uid the user id:

$refresh (FALSE) when TRUE, refreshes the cache for $uid:

Return value

string html representation of userbadges

1 call to user_badges_for_uid()
views_handler_field_user_badges_user_uid::render in includes/views/views_handler_field_user_badges_user_uid.inc
Render the field.

File

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

Code

function user_badges_for_uid($uid, $refresh = FALSE) {
  static $cache;
  if ($uid) {
    if (isset($cache[$uid]) && !$refresh) {
      return $cache[$uid];
    }
    else {

      // TODO: User can also have role badges.
      $user_badges = user_badges_get_badges($uid);
      $account = user_load($uid);
      foreach ($account->roles as $rid => $role_name) {
        $rb = user_badges_get_roles($rid, array(
          'returnbadges' => TRUE,
        ));
        foreach ($rb as $rid => $b) {
          $user_badges[$b->bid] = $b;
        }
      }
      foreach ($user_badges as $badge) {
        $badges[] = theme('user_badge', array(
          'badge' => $badge,
          'account' => $account,
        ));
      }
      $cache[$uid] = isset($badges) ? theme('user_badge_group', array(
        'badgeimages' => $badges,
      )) : '';
      return $cache[$uid];
    }
  }
}