You are here

function _uc_roles_get_choices in Ubercart 6.2

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

Gets available roles for granting on product purchase.

Parameters

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

Return value

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

4 calls to _uc_roles_get_choices()
uc_roles_feature_form in uc_roles/uc_roles.module
Form builder for hook_product_feature.
uc_roles_feature_settings in uc_roles/uc_roles.module
Form builder for role settings.
uc_roles_store_status in uc_roles/uc_roles.module
Implements hook_store_status().
uc_roles_user_form in uc_roles/uc_roles.module
Implements hook_user_form().

File

uc_roles/uc_roles.module, line 1085

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;
}