function oa_core_get_group_from_node in Open Atrium Core 7.2
Helper function to return the id of the space/group that contains the nid node
This function is called a lot, so it needs to be fast Do not use node_load here!
Parameters
$node: A numeric NID or a complete $node object.
$allowed_types: an array of content types that this node can be part of.
Return value
A numeric NID of the group that this content is part of. If $node is a group or not member of a group, its NID is returned.
6 calls to oa_core_get_group_from_node()
- oa_core_add_member_render in plugins/
content_types/ oa_core_add_member.inc - Render callback for the content visibility panel.
- oa_core_members_widget_render in plugins/
content_types/ oa_core_members_widget.inc - Main render function for oa_core_members_widget.
- oa_core_summary_render in plugins/
content_types/ oa_core_summary.inc - Render callback for the content visibility panel.
- oa_messages_determine_user_notifiers in modules/
oa_messages/ oa_messages.module - Determine's a users's notifiers based on message type and message content.
- oa_users_add_external_user_render in modules/
oa_users/ plugins/ content_types/ oa_users_add_external_user.inc - Render callback for the add external user plugin.
File
- includes/
oa_core.util.inc, line 1161 - Code for Utility functions for OpenAtrium spaces
Code
function oa_core_get_group_from_node($node, $allowed_types = array(
OA_SPACE_TYPE,
OA_GROUP_TYPE,
)) {
$cache =& drupal_static('oa_core_groups', array());
// Find the NID in case a $node object was passed in..
if (is_object($node) && !empty($node->nid)) {
$nid = $node->nid;
if (!empty($allowed_types) && in_array($node->type, $allowed_types)) {
$cache[$nid] = $nid;
}
}
else {
$nid = $node;
}
if (isset($cache[$nid])) {
return $cache[$nid];
}
$query = db_select('og_membership', 'f');
$query
->leftJoin('node', 'n', 'n.nid = f.gid');
$result = $query
->fields('f', array(
'gid',
))
->condition('f.etid', $nid)
->condition('f.group_type', 'node')
->condition('f.entity_type', 'node')
->condition('f.field_name', OA_SPACE_FIELD)
->condition('n.type', $allowed_types)
->execute()
->fetchAssoc();
if (!empty($result)) {
$cache[$nid] = $result['gid'];
}
else {
$cache[$nid] = $nid;
}
return $cache[$nid];
}