You are here

function og_subgroups_delete_group in Subgroups for Organic groups 6

Handle the deletion of a group

If the group is inside a hierarchy, we need to remove the relationship for the groups parents. We also need to reassign the groups immediate children to become children of the groups parent.

Parameters

$group: The group node object

1 call to og_subgroups_delete_group()
og_subgroups_nodeapi in ./og_subgroups.module
Implementation of hook_nodeapi().

File

./og_subgroups.module, line 177
Maintains a hierarchy of groups created by the orgainc groups module.

Code

function og_subgroups_delete_group($group) {
  og_subgroups_include('tree');

  // Determine the parent of this group
  $parent = og_subgroups_get_group_parent($group);

  // Determine the immediate children of this group
  if ($children = og_subgroups_get_group_children($group)) {

    // Iterate the children, assigning them to the groups parent
    foreach ($children as $child_id => $child) {
      og_subgroups_set_parent($child, isset($parent->nid) ? $parent->nid : 0);
    }
  }

  // Remove the relationship with the parent from the group
  db_query("DELETE FROM {og_subgroups} WHERE gid = %d", $group->nid);
}