function og_subgroups_set_parent in Subgroups for Organic groups 6
Set the parent of a given group
Parameters
$node: The node object, or node id
$parent: The parent node object, or node id. If set to 0 or omitted, any existing parent for the node will be removed
Return value
Boolean indication if operation preformed was successful
2 calls to og_subgroups_set_parent()
- og_subgroups_delete_group in ./
og_subgroups.module - Handle the deletion of a group
- og_subgroups_nodeapi in ./
og_subgroups.module - Implementation of hook_nodeapi().
File
- ./
og_subgroups.module, line 90 - Maintains a hierarchy of groups created by the orgainc groups module.
Code
function og_subgroups_set_parent($node, $parent = NULL) {
// Either objects or node ids can be passed in
$nid = is_object($node) ? $node->nid : $node;
$pid = is_object($parent) ? $parent->nid : $parent;
// Make sure we have at least a valid nid
// We don't check $pid because it could be NULL or zero
if (is_numeric($nid) && !($nid > 0)) {
return FALSE;
}
// Be safe and make sure we don't have the same node
if ($nid == $pid) {
return FALSE;
}
// Remove any existing parent for this group
$success = db_query("DELETE FROM {og_subgroups} WHERE gid = %d", $nid);
// Only save a new setting if a parent was specified
if ($success && $pid) {
// Save the new parent
$record = new stdClass();
$record->gid = $nid;
$record->parent = $pid;
$success = drupal_write_record('og_subgroups', $record);
}
return $success ? TRUE : FALSE;
}