function og_ungroup in Organic groups 7
Same name and namespace in other branches
- 7.2 og.module \og_ungroup()
Delete an association (e.g. unsubscribe) of an entity to a group.
Parameters
$entity_type: The entity type (e.g. "node" or "user").
$entity: The entity to set the association.
$save: Optioanl; TRUE if fields value shoudl be saved. Defaults to TRUE.
Return value
The entity with the fields updated.
5 calls to og_ungroup()
- OgGroupAndUngroup::testGroupAndUngroup in ./
og.test - Test group and ungroup of content.
- OgGroupMembership::testGroupMembershipCrud in ./
og.test - Test group group membership create, update and delete.
- og_rules_remove_entity_from_group in ./
og.rules.inc - Action: Remove entity from group.
- og_ui_confirm_unsubscribe_submit in og_ui/
og_ui.pages.inc - Submit handler; Confirm OG unsubscription.
- og_ui_user_operations_deny in og_ui/
og_ui.module - Callback function for admin mass denying users.
File
- ./
og.module, line 1732 - Enable users to create and manage groups with roles and permissions.
Code
function og_ungroup($gid, $entity_type, $entity, $save = TRUE) {
$entity = og_load_entity($entity_type, $entity);
$property = OG_AUDIENCE_FIELD;
if (!empty($entity->{$property})) {
$wrapper =& $entity->{$property}[LANGUAGE_NONE];
$existing_key = FALSE;
if (!empty($wrapper)) {
foreach ($wrapper as $key => $value) {
if ($gid == $value['gid']) {
$existing_key = $key;
break;
}
}
}
if ($existing_key !== FALSE) {
unset($wrapper[$existing_key]);
if ($save) {
entity_save($entity_type, $entity);
og_invalidate_cache();
// Group might be deleted, so don't try to remove roles that don't
// exist.
$group = og_load($gid);
if ($entity_type == 'user' && $group) {
foreach (og_get_user_roles($gid, $entity->uid) as $rid) {
og_role_revoke($gid, $entity->uid, $rid);
}
}
}
}
}
return $entity;
}