You are here

function role_delegation_save in Role Delegation 7

2 calls to role_delegation_save()
role_delegation_delegate_roles_action in ./role_delegation.module
role_delegation_roles_form_submit in ./role_delegation.module
Saves the roles assigned to the account given in the form.

File

./role_delegation.module, line 127
This module allows site administrators to grant some roles the authority to change roles assigned to users, without them needing the 'administer access control' permission.

Code

function role_delegation_save($uids, $roles_change) {
  $rolenames = user_roles(TRUE);
  foreach ($roles_change as $rid => $value) {
    if (!empty($value)) {

      // Use the role name for changed roles.
      $roles_change[$rid] = $rolenames[$rid];
    }
  }
  $accounts = user_load_multiple($uids);
  foreach ($accounts as $account) {
    $roles_current = $account->roles;
    $roles = array_filter($roles_change + $roles_current);
    user_save($account, array(
      'roles' => $roles,
    ));
  }
}