You are here

function user_badges_roles_form in User Badges 7.3

Same name and namespace in other branches
  1. 5 user_badges.module \user_badges_roles_form()
  2. 6.2 user_badges.admin.inc \user_badges_roles_form()
  3. 6 user_badges.admin.inc \user_badges_roles_form()
  4. 7.4 includes/user_badges.admin.inc \user_badges_roles_form()
  5. 7 user_badges.admin.inc \user_badges_roles_form()
  6. 7.2 user_badges.admin.inc \user_badges_roles_form()

Form to associated badges with roles.

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

File

./user_badges.admin.inc, line 644
@brief User Badges admin functions

Code

function user_badges_roles_form($form, &$form_state) {

  // No badges for the anonymous role.
  $roles = user_roles(TRUE);
  $role_badges = user_badges_get_roles(NULL, array(
    'returnbadges' => TRUE,
  ));
  $form['blocked'] = array(
    '#type' => 'fieldset',
    '#title' => t('Blocked Badge'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );
  $form['roles'] = array(
    '#type' => 'fieldset',
    '#title' => t('Role Badges'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );

  //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;
      }
      $form['blocked'][0] = array(
        '#type' => 'select',
        '#title' => t('blocked user'),
        '#empty_option' => '- None -',
        '#options' => $options,
        '#default_value' => isset($role_badges[0]) ? $role_badges[0]->bid : '',
      );
      foreach ($roles as $rid => $role) {
        $form['roles'][$rid] = array(
          '#type' => 'select',
          '#title' => check_plain($role),
          '#empty_option' => '- None -',
          '#options' => $options,
          '#default_value' => isset($role_badges[$rid]) ? $role_badges[$rid]->bid : '',
        );
      }
    }
  }
  else {
    $form['blocked'][0] = array(
      '#type' => 'textfield',
      '#title' => t('blocked user'),
      '#size' => 40,
      '#maxlength' => 255,
      '#autocomplete_path' => 'user_badges/autocomplete',
      '#default_value' => isset($role_badges[0]) ? $role_badges[0]->name . ' ' . t('(Badge ID') . ' ' . $role_badges[0]->bid . ')' : '',
      '#field_suffix' => isset($role_badges[0]) ? ' ' . t('Current:') . ' ' . _user_badges_build_image($role_badges[0]) : '',
    );
    foreach ($roles as $rid => $role) {
      $form['roles'][$rid] = array(
        '#type' => 'textfield',
        '#title' => check_plain($role),
        '#maxlength' => 255,
        '#autocomplete_path' => 'user_badges/autocomplete',
        '#default_value' => isset($role_badges[$rid]) ? $role_badges[$rid]->name . ' ' . t('(Badge ID') . ' ' . $role_badges[$rid]->bid . ')' : '',
        '#field_suffix' => isset($role_badges[$rid]) ? ' ' . t('Current:') . ' ' . _user_badges_build_image($role_badges[$rid]) : '',
      );
    }
  }
  $form[] = array(
    '#type' => 'submit',
    '#value' => t('Save Role Badges'),
  );
  return $form;
}