You are here

function _csm_relevant_role_array in Custom Submit Messages 7

2 calls to _csm_relevant_role_array()
csm_form_alter in ./csm.module
Implements hook_form_alter().
csm_message_alter in ./csm.module
Implements hook_message_alter().

File

./csm.module, line 688
The main module file for Custom Submit Messages.

Code

function _csm_relevant_role_array($user) {

  // The $user has more than one role (as they almost always will do) so we
  // need to work out which role is relevant for our purposes
  $csm_settings = variable_get('csm_attributes', NULL);
  if ($csm_settings == NULL) {
    $relevant_roles[] = 'global';
    return $relevant_roles;
  }
  else {
    foreach ($csm_settings as $rid => $settings) {
      if ($settings['checkbox'] == 1) {
        break;
      }
    }
    if ($settings['checkbox'] == 0) {

      // The csm_settings have been set, but none of the checkboxes are checked
      // so we only need to deal with language-specific messages (not role specific)
      $relevant_roles[] = 'global';
      return $relevant_roles;
    }
  }

  // Loop through each role and if checkbox is checked and user has role then
  // add that role to our array
  foreach ($user->roles as $rid => $role) {
    if (array_key_exists($rid, $csm_settings) && $csm_settings[$rid]['checkbox'] == 1) {
      $relevant_roles[] = $rid;
      $weights[] = $csm_settings[$rid]['weight'];
    }
  }
  array_multisort($weights, $relevant_roles);
  $relevant_roles[] = 'global';
  return $relevant_roles;
}