You are here

function og_node_groups_distinguish in Organic groups 6.2

Same name and namespace in other branches
  1. 5.8 og.module \og_node_groups_distinguish()
  2. 5 og.module \og_node_groups_distinguish()
  3. 5.3 og.module \og_node_groups_distinguish()
  4. 5.7 og.module \og_node_groups_distinguish()
  5. 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

A two element array containing 'accessible' and 'inaccessible' keys.

See also

og_form_add_og_audience()

3 calls to og_node_groups_distinguish()
og_form_add_og_audience in ./og.module
Add OG audience fields to a given form.
og_nodeapi in ./og.module
Implementation of hook_nodeapi().
og_preprocess_node in ./og.module
Preprocessor for Node template.

File

./og.module, line 2049
Code for the Organic Groups module.

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 = db_placeholders($groups_names_both);
    $sql = 'SELECT n.nid FROM {node} n WHERE n.nid IN (' . $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;
}