You are here

function user_badges_change_form in User Badges 7.3

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

Form to change badges of a user

1 string reference to 'user_badges_change_form'
user_badges_page in ./user_badges.module
Define the page on user/uid/badges/edit and user/%user/edit/badges.

File

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

Code

function user_badges_change_form($form, &$form_state, $account) {
  $form = array();
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $account->uid,
  );
  $form['add'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add Badges'),
    '#weight' => 3,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  //Determine which selector type the user wants to use to set badges from their settings

  //If the user wants to use the drop-down selector, display that if there are records in the db
  if (variable_get('user_badges_selector_type', 1) == 0) {

    //First, load all the available badges from the database by calling the following helper function
    $result = user_badges_load_badges();

    //Display the drop-down only if we get any records
    if ($result
      ->rowCount()) {
      foreach ($result as $badge) {
        $options[$badge->bid] = t('Badge') . ' ' . $badge->bid . ' ' . '-' . ' ' . $badge->name;
      }

      //Initialize the $options array, which will contain all the badges fetched from the db

      //Add a - None - option to the badge list as Drupal core won't give it to us automatically

      //because it is a multi select list!!
      $options[-1] = '- None -';

      //Add the drop-down multi select box to add badges
      $form['add']['add_drop_down'] = array(
        '#type' => 'select',
        '#title' => t('New Badges'),
        '#options' => $options,
        '#multiple' => TRUE,
      );
    }
  }
  else {
    for ($i = 1; $i <= 5; $i++) {

      //Add the autocomplete boxes to add badges
      $form['add']['add_autocomplete' . $i] = array(
        '#type' => 'textfield',
        '#title' => t('New Badge @number', array(
          '@number' => $i,
        )),
        '#size' => 40,
        '#maxlength' => 255,
        '#autocomplete_path' => 'user_badges/autocomplete',
      );
    }
  }
  if (isset($account->badges_all) && count($account->badges_all)) {
    $form['remove'] = array(
      '#type' => 'fieldset',
      '#title' => t('Remove Badges'),
      '#weight' => 5,
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    foreach ($account->badges_all as $badge) {
      $form['remove'][$badge->bid] = array(
        '#type' => 'checkbox',
        '#title' => theme('user_badge', array(
          'badge' => $badge,
          'account' => $account,
        )),
        '#return_value' => 1,
        '#default_value' => 0,
        '#description' => check_plain($badge->name),
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update Badges'),
    '#weight' => 10,
  );
  return $form;
}