You are here

function user_badges_user_load in User Badges 7.3

Same name and namespace in other branches
  1. 7 user_badges.module \user_badges_user_load()
  2. 7.2 user_badges.module \user_badges_user_load()

Implements hook_user_load().

Gets all badges for the user and the limited badges.

File

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

Code

function user_badges_user_load($users) {
  static $user_badges = array();
  foreach ($users as $uid => $account) {

    // Only handle authenticated users.
    if ($uid > 0) {

      // Have we loaded this user before?
      if (isset($user_badges[$uid])) {
        $users[$uid]->badges = $user_badges[$uid];
      }
      else {
        $user_badges[$uid] = array();

        // Get all user badges for this user, regardless of
        // whether we filter the ones we show.
        // @TODO: This also doesn't get role badges.
        $badges_all = user_badges_get_badges($uid, array(
          'nolimit' => TRUE,
        ));
        $users[$uid]->badges_all = $badges_all;
        $users[$uid]->badges_count = count($badges_all);

        // If there is a limit set, then, display the badges according to the limit
        if (variable_get('user_badges_showone', 0)) {
          $user_badges[$uid] = user_badges_get_badges($uid);
          $users[$uid]->badges = $user_badges[$uid];
        }
        else {
          $user_badges[$uid] = $badges_all;
          $users[$uid]->badges = $user_badges[$uid];
        }
      }
    }
  }
}