public function LdapTestFunctions::removeRoleFromUser in Lightweight Directory Access Protocol (LDAP) 8.2
Same name and namespace in other branches
- 7.2 ldap_test/LdapTestFunctions.class.php \LdapTestFunctions::removeRoleFromUser()
File
- ldap_test/
LdapTestFunctions.class.php, line 126
Class
Code
public function removeRoleFromUser($user, $role_name) {
if (is_numeric($user)) {
$user = user_load($user);
}
$key = array_search($role_name, $user->roles);
if ($key == TRUE) {
// Get the rid from the roles table.
$roles = user_roles(TRUE);
$rid = array_search($role_name, $roles);
if ($rid != FALSE) {
// Make a copy of the roles array, without the deleted one.
$new_roles = array();
foreach ($user->roles as $id => $name) {
if ($id != $rid) {
$new_roles[$id] = $name;
}
}
user_save($user, array(
'roles' => $new_roles,
));
}
}
}