function views_bulk_operations_user_roles_action in Views Bulk Operations (VBO) 6.3
Same name and namespace in other branches
- 6 actions/user_roles.action.inc \views_bulk_operations_user_roles_action()
- 7.3 actions/user_roles.action.inc \views_bulk_operations_user_roles_action()
1 string reference to 'views_bulk_operations_user_roles_action'
- views_bulk_operations_views_default_views in ./
views_bulk_operations.views_default.inc - Implementation of hook_views_default_views().
File
- ./
user_roles.action.inc, line 47
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());
$result = db_query("SELECT rid, name FROM {role} WHERE rid IN (%s)", implode(',', 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,
));
}