function oa_core_get_groups_by_parent in Open Atrium Core 7.2
Get child Spaces or Groups.
Parameters
int $nid: The NID of the Space or Group to check, or an array of nids
string|NULL $bundle: (optional) The node type (default: OA_SPACE_TYPE). If NULL is passed, it will include all node types.
int|NULL $status: (optional) If specified, the node status (ex. NODE_PUBLISHED or NODE_NOT_PUBLISHED) to look for. If not specified, it return nodes of either status.
bool $include_archived: (optional) Whether to include archived nodes or not. By default, archived items aren't included.
int|NULL $account: (optional) user to control node acess. If Null, use current user
bool $subspaces: (optional) determine if subspaces are also fetched, or if just top level children are fetched
bool $inheritance: (optional) if TRUE, only return subspaces that have inheritance enabled
Return value
array Array of children NIDs.
2 calls to oa_core_get_groups_by_parent()
- oa_core_get_groups_by_user in includes/
oa_core.util.inc - Get the group IDs of all the groups a user is an approved member of.
- oa_core_node_update in includes/
oa_core.access.inc - Implements hook_node_update().
File
- includes/
oa_core.util.inc, line 433 - Code for Utility functions for OpenAtrium spaces
Code
function oa_core_get_groups_by_parent($nids, $bundle = OA_SPACE_TYPE, $status = NULL, $include_archived = FALSE, $account = NULL, $subspaces = FALSE, $inheritance = TRUE) {
if ($nids == 0) {
return oa_core_get_top_parents($bundle, $status, $include_archived, $account);
}
if (!isset($account)) {
global $user;
$uid = $user->uid;
}
elseif (is_numeric($account)) {
$uid = $account;
}
else {
$uid = $account->uid;
}
if (is_array($nids)) {
$hash = md5(serialize($nids));
}
else {
$hash = $nids;
}
$cid = oa_core_get_cache_id(OA_CACHE_GROUPS_BY_PARENT, $hash . '_' . $uid, $include_archived, array(
serialize($bundle),
$status,
$subspaces,
));
if (oa_core_get_cache(OA_CACHE_GROUPS_BY_PARENT, $cid, $result)) {
return $result;
}
if (!is_array($nids)) {
$nids = array(
$nids,
);
}
$query = db_select('node', 'n');
$query
->join('og_membership', 'f', "n.nid = f.etid AND f.entity_type = 'node'");
$query
->fields('n', array(
'nid',
))
->orderBy('n.title');
// to find all subspaces, we query *all* spaces with parents
// otherwise, if just getting top level children we can filter it here.
if (!$subspaces) {
$query
->condition('f.gid', $nids, 'IN');
$query
->addTag('node_access');
}
if (isset($bundle)) {
if (is_array($bundle)) {
$query
->condition('n.type', $bundle, 'IN');
}
else {
$query
->condition('n.type', $bundle);
}
}
if (isset($status)) {
$query
->condition('n.status', $status);
}
if (module_exists('flag') && !$include_archived) {
if ($flag = flag_get_flag('trash')) {
$query
->leftJoin('flagging', 'a', "a.fid = :fid AND a.entity_id = n.nid", array(
':fid' => $flag->fid,
));
// This makes sure that archived content isn't included, because 'uid'
// will be NULL if the join didn't connect anything.
$query
->isNull('a.uid');
}
}
if ($subspaces) {
$query
->fields('f', array(
'gid',
));
$query
->condition('f.etid', $nids, 'NOT IN');
$query
->join('field_data_og_user_inheritance', 'inh', "inh.entity_id = f.gid && f.group_type = 'node'");
$query
->fields('inh', array(
'og_user_inheritance_value',
));
$result = $query
->execute()
->fetchAll();
// to get a list of all subspaces, we can now loop through the list of all parents recursively
// to build our children list
$all_parents = array();
foreach ($result as $parent) {
if (!$inheritance || $parent->og_user_inheritance_value == 1) {
$all_parents[$parent->gid][] = $parent->nid;
}
}
$result = _oa_core_get_all_children($all_parents, $nids);
}
else {
$result = $query
->execute()
->fetchCol(0);
}
$result = drupal_map_assoc($result);
oa_core_set_cache(OA_CACHE_GROUPS_BY_PARENT, $cid, $result);
return $result;
}