function views_bulk_operations_user_roles_action in Views Bulk Operations (VBO) 6
Same name and namespace in other branches
- 6.3 user_roles.action.inc \views_bulk_operations_user_roles_action()
- 7.3 actions/user_roles.action.inc \views_bulk_operations_user_roles_action()
File
- actions/
user_roles.action.inc, line 58
Code
function views_bulk_operations_user_roles_action(&$user, $context) {
$roles = $user->roles;
$selected = (is_array($context['add_roles']) ? $context['add_roles'] : array()) + (is_array($context['remove_roles']) ? $context['remove_roles'] : array());
$placeholders = db_placeholders($selected);
$result = db_query("SELECT rid, name FROM {role} WHERE rid IN ({$placeholders})", array_keys($selected));
while ($role = db_fetch_object($result)) {
if (isset($context['add_roles'][$role->rid])) {
$add_roles[$role->rid] = $role->name;
}
if (isset($context['remove_roles'][$role->rid])) {
$remove_roles[$role->rid] = $role->name;
}
}
if (!empty($add_roles)) {
$roles += $add_roles;
}
if (!empty($remove_roles)) {
$roles = array_diff($roles, $remove_roles);
}
user_save($user, array(
'roles' => $roles,
));
}