function og_roles_override in Organic groups 7
Same name and namespace in other branches
- 7.2 og.module \og_roles_override()
Create new roles, based on the default roles and permissions.
Parameters
$gid: The group ID.
Return value
The newly created roles keyed by role ID and role name as the value. Or FALSE if no roles were created.
2 calls to og_roles_override()
- og_field_crud_group in ./
og.field.inc - Create update or delete a group, based on the field CRUD.
- og_ui_og_migrate_upgrade_group_visibility in og_ui/
plugins/ og_migrate/ upgrade_group_visibility.inc - OG Migrate callback; Upgrade user subscription to groups.
File
- ./
og.module, line 2706 - Enable users to create and manage groups with roles and permissions.
Code
function og_roles_override($gid) {
// Check if roles aren't already overriden. We can't use
// og_is_group_default_access() as the field is already set, so we
// check to see if there are new roles in the database and compare
// them with the default roles.
// TODO: We can add a key to the $group object that will indicate this
// if performance will be poor.
if ($roles = og_roles($gid, NULL, TRUE)) {
return;
}
$rids = array();
// Make sure roles doesn't exist already by looking for a row with the group
// ID in {og_role} table.
$perms = og_get_global_permissions();
foreach (og_get_global_roles() as $rid => $name) {
$role = new stdClass();
$role->name = $name;
$role->gid = $gid;
og_role_save($role);
$rids[$role->rid] = $role->name;
og_role_change_permissions($role->rid, $perms[$rid]);
// Remap roles.
$query = db_update('og_users_roles')
->fields(array(
'rid' => $role->rid,
))
->condition('rid', $rid)
->condition('gid', $gid)
->execute();
}
return $rids;
}