You are here

function og_node_groups_distinguish in Organic groups 6

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.2 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.

3 calls to og_node_groups_distinguish()
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.
og_nodeapi in ./og.module
Implementation of hook_nodeapi().
og_preprocess_node in ./og.module
Enrich non group nodes with the list og groups that the node belongs to.

File

./og.module, line 1987

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;
}