You are here

function user_badges_userweight_page in User Badges 7.3

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

Define the page on user/uid/badges.

1 string reference to 'user_badges_userweight_page'
user_badges_menu in ./user_badges.module
Implements hook_menu().

File

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

Code

function user_badges_userweight_page($account) {
  global $user;
  drupal_set_title(t('Badges for %user_name', array(
    '%user_name' => format_username($account),
  )), PASS_THROUGH);

  // Do we have the right to rearrange badges?
  if (variable_get('user_badges_userweight', 0) && ($account->uid == $user->uid || user_access('change badge assignments'))) {

    // If the setting allows it and we are the badge owner or somebody with permission, yes.
    return drupal_get_form('user_badges_userweight_form', $account);
  }
  else {
    $whoelse = arg(3) == 'whoelse';

    // Otherwise, just list the badges on the page.
    $user_badges = user_badges_get_badges($account->uid, array(
      'nolimit' => TRUE,
    ));
    $badges = array();
    foreach ($user_badges as $badge) {
      $item = array(
        theme('user_badge', array(
          'badge' => $badge,
          'account' => $account,
        )),
        array(
          'data' => check_plain($badge->name),
          'class' => 'user-badge-name',
        ),
      );
      if ($whoelse) {
        $query = db_select('user_badges_user', 'ubu')
          ->condition('ubu.bid', $badge->bid, '=')
          ->condition('ubu.uid', $account->uid, '<>');
        $u = $query
          ->join('users', 'u', 'u.uid=ubu.uid');
        $query
          ->fields($u);
        $result = $query
          ->execute();
        $accts = array();
        foreach ($result as $acct) {

          // This allows other username functions to intercede.
          $accts[] = format_username($acct);
        }
        if (!$accts) {
          $accts[] = t('None');
        }
        $item[] = array(
          'data' => theme('item_list', array(
            'items' => $accts,
          )),
          'class' => 'user-badges-whoelse',
        );
      }
      $badges[] = $item;
    }
    if ($badges) {
      $badges = array(
        theme('table', array(
          'rows' => $badges,
          'attributes' => array(
            'style' => 'width: auto;',
          ),
        )),
      );
      return theme('user_badge_group', array(
        'badgeimages' => $badges,
      ));
    }
    else {
      return t('This user is not currently assigned any badges.');
    }
  }
}