You are here

function _uc_roles_get_choices in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_roles/uc_roles.module \_uc_roles_get_choices()

Gets available roles for granting on product purchase.

Parameters

array $exclude: A list of role ids to exclude from the list.

Return value

array An assoc array with key = rid and value = role name.

5 calls to _uc_roles_get_choices()
uc_roles_feature_form in uc_roles/uc_roles.module
Form builder for hook_uc_product_feature().
uc_roles_feature_settings in uc_roles/uc_roles.module
Form builder for role settings.
uc_roles_form_user_profile_form_alter in uc_roles/uc_roles.module
Implements hook_form_user_profile_form_alter().
uc_roles_uc_store_status in uc_roles/uc_roles.module
Implements hook_uc_store_status().
uc_roles_user_presave in uc_roles/uc_roles.module
Implements hook_user_presave().

File

uc_roles/uc_roles.module, line 941
Grants roles upon accepted payment of products.

Code

function _uc_roles_get_choices($exclude = array()) {
  $output = array();

  // Get roles from Drupal, excluding Anonymous and Authenticated.
  $roles = user_roles(TRUE);
  unset($roles[DRUPAL_AUTHENTICATED_RID]);

  // User set specific roles that we must use?
  $selected = variable_get('uc_roles_default_role_choices', array());

  // If there's none, or if none are checked, use all of em.
  $default = empty($selected) || array_sum($selected) == 0;
  foreach ($roles as $rid => $name) {
    if ($default || !empty($selected[$rid]) && !in_array($rid, $exclude)) {
      $output[$rid] = $roles[$rid];
    }
  }
  return $output;
}