You are here

function user_badges_userweight_form in User Badges 6.2

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

form for users to weight their own badges

1 string reference to 'user_badges_userweight_form'
user_badges_userweight_page in ./user_badges.module
Define the page on user/uid/badges.

File

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

Code

function user_badges_userweight_form($form_state, $account) {
  $allbadges = $account->badges_all;

  // Header row for the badge reweighting list.
  $form['header'] = array(
    '#type' => 'value',
    '#value' => array(
      array(
        'data' => t('Name'),
      ),
      array(
        'data' => t('Badge'),
      ),
      array(
        'data' => t('Weight'),
      ),
    ),
  );

  // We need to know what the weight delta will be, which depends on the number
  // of badges we will list.
  $delta = 0;
  foreach ($allbadges as $badge) {
    if (!$badge->fixedweight) {
      $delta++;
    }
  }

  // Build a table listing the appropriate badges.
  foreach ($allbadges as $badge) {

    // We cannot include fixed weight badges.
    if ($badge->fixedweight) {
      continue;
    }

    // Set the badge default weight.
    $weight = $badge->weight;
    if (isset($badge->userweight)) {
      $weight = $badge->userweight;
    }
    $form['name'][$badge->bid] = array(
      '#value' => check_plain($badge->name),
    );
    $form['badge'][$badge->bid] = array(
      '#value' => theme('user_badge', $badge, $account),
    );
    $form['weight'][$badge->bid] = array(
      '#type' => 'weight',
      '#default_value' => $weight,
      '#delta' => $delta,
      '#attributes' => array(
        'class' => 'user_badges_userweight_element',
      ),
    );
  }
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $account->uid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}