function og_determine_context_get_group in Organic groups 6
Same name and namespace in other branches
- 6.2 og.module \og_determine_context_get_group()
Helper function; Get an appropriate group node to be set as the group conext.
If a group post belongs to multiple group nodes, the logic for determining the group node is: 1) The group we showed on the prior page view (if any). 2) The only or one of the group(s) the current user is a member of. 3) The 'first' group in $node->og_groups.
Parameters
$node: The node that the context should be retrieved from.
$account: (optional) The account to check, if not given use currently logged in user.
Return value
The group node if exists and accesiable by the user.
See also
1 call to og_determine_context_get_group()
- og_determine_context in ./
og.module - Set group context using the menu system.
File
- ./
og.module, line 508
Code
function og_determine_context_get_group($node, $account = NULL) {
if (empty($account)) {
global $user;
$account = $user;
}
if (og_is_group_type($node->type)) {
$group_node = $node;
}
elseif (og_is_group_post_type($node->type) && !empty($node->og_groups)) {
// Post may be is in multiple groups ...
if (isset($_SESSION['og_last']) && in_array($_SESSION['og_last'], $node->og_groups)) {
$group = $_SESSION['og_last'];
}
elseif (!empty($user->og_groups) && ($gid = current(array_intersect($node->og_groups, array_keys($user->og_groups))))) {
$group = $gid;
}
else {
// No user is logged in, or none of the node's groups are the user's groups
$group = current($node->og_groups);
}
if (!empty($group)) {
$group_node = node_load($group);
}
}
// Make sure user has view access to the group node.
if (!empty($group_node) && node_access('view', $group_node, $account)) {
return $group_node;
}
}