You are here

function _spaces_og_group_options in Spaces 6.2

Same name and namespace in other branches
  1. 5.2 spaces_og.module \_spaces_og_group_options()
  2. 5 spaces.module \_spaces_og_group_options()
  3. 6 spaces_og/spaces_og.module \_spaces_og_group_options()

Generates an array of groups that a node could potentially be a member of based on enabled spaces features and optionally the specified user's groups

1 call to _spaces_og_group_options()
_spaces_og_form_alter_node in spaces_og/spaces_og.module
Group-enabled node form_alter()

File

spaces_og/spaces_og.module, line 1083

Code

function _spaces_og_group_options($type, $uid = 0) {
  $types = spaces_features_map('node');
  $group_options = array();
  $where = $join = '';
  $args = array();

  // Only join to features table if this node is part of a feature.
  if (isset($types[$type])) {
    $join .= " JOIN {spaces_features} sf ON sf.sid = og.nid";
    $where .= " AND sf.id = '%s' AND sf.value != '%s'";
    $args = array(
      $types[$type],
      0,
    );
  }
  if ($uid) {
    $join .= " JOIN {og_uid} ogu ON ogu.nid = og.nid";
    $where .= " AND ogu.uid = %d AND ogu.is_active >= 1";
    $args[] = $uid;
  }
  $result = db_query("SELECT og.nid, n.title\n      FROM {og} og\n      JOIN {node} n ON og.nid = n.nid\n      {$join}\n    WHERE n.status = 1\n      {$where}\n    ORDER BY n.title ASC", $args);
  while ($group = db_fetch_object($result)) {
    $group_options[$group->nid] = $group->title;
  }
  return $group_options;
}