You are here

function user_badges_userweight_form in User Badges 7.3

Same name and namespace in other branches
  1. 6.2 user_badges.module \user_badges_userweight_form()
  2. 6 user_badges.module \user_badges_userweight_form()
  3. 7.4 user_badges.module \user_badges_userweight_form()
  4. 7 user_badges.module \user_badges_userweight_form()
  5. 7.2 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 352
@brief User Badges module file

Code

function user_badges_userweight_form($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 = 1;
  foreach ($allbadges as $badge) {
    if (!$badge->fixedweight) {
      $delta++;
    }
  }

  // Build a table listing the appropriate badges.
  $vars = array(
    'account' => $account,
  );
  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(
      '#markup' => check_plain($badge->name),
    );
    $vars['badge'] = $badge;
    $form['badge'][$badge->bid] = array(
      '#markup' => theme('user_badge', $vars),
    );
    $form['weight'][$badge->bid] = array(
      '#type' => 'weight',
      '#default_value' => $weight,
      '#delta' => $delta,
      '#tree' => TRUE,
      '#attributes' => array(
        'class' => array(
          'user_badges_userweight_element',
        ),
      ),
    );
  }
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $account->uid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}