function og_node_groups_distinguish in Organic groups 5.3
Same name and namespace in other branches
- 5.8 og.module \og_node_groups_distinguish()
- 5 og.module \og_node_groups_distinguish()
- 5.7 og.module \og_node_groups_distinguish()
- 6.2 og.module \og_node_groups_distinguish()
- 6 og.module \og_node_groups_distinguish()
Iterate over a set of groups and separate out those that are inaccessible to the current user. Don't return groups of which the current user is a member, unless $exclude_joined=FALSE is passed. Used in og_form_add_og_audience() and node.tpl.php.
Return value
array A two element array containing 'accessible' and 'inaccessible' keys.
2 calls to og_node_groups_distinguish()
- node.tpl.php in ./
node.tpl.php - og_form_add_og_audience in ./
og.module - Helper method to add OG audience fields to a given form. This is lives in a separate function from og_form_alter() so it can be shared by other OG contrib modules.
File
- ./
og.module, line 1649
Code
function og_node_groups_distinguish($groups_names_both, $exclude_joined = TRUE) {
global $user;
$current_groups = array(
'accessible' => array(),
'inaccessible' => array(),
);
if (empty($groups_names_both)) {
// Do nothing.
}
else {
$placeholders = array_fill(0, count($groups_names_both), '%d');
$sql = 'SELECT n.nid FROM {node} n WHERE n.nid IN (' . implode(', ', $placeholders) . ')';
$result = db_query(db_rewrite_sql($sql), array_keys($groups_names_both));
while ($row = db_fetch_object($result)) {
$current_groups['accessible'][$row->nid]['title'] = $groups_names_both[$row->nid];
}
foreach ($groups_names_both as $gid => $title) {
if (!in_array($gid, array_keys($current_groups['accessible']))) {
$current_groups['inaccessible'][$gid] = $gid;
}
}
if ($exclude_joined) {
// Don't return groups that the user has already joined (default).
$current_groups['accessible'] = array_diff_assoc($current_groups['accessible'], $user->og_groups);
}
}
return $current_groups;
}