You are here

function og_subgroups_parents_select in Subgroups for Organic groups 5.3

File

./og_subgroups.module, line 527
Maintains a hierarchy of group/subgroup relationships.

Code

function og_subgroups_parents_select($title, $name, $selected, $gid, $type, $exclude = array()) {
  $child_types = variable_get('og_subgroups_' . $type . '_parents', array());
  if (count($child_types) == 0) {
    return "";
  }
  $options = array();
  $query = "SELECT og.nid, n.title FROM {og} og INNER JOIN {node} n where og.nid=n.nid AND og.nid <> %d";
  $add = " and (";
  foreach ($child_types as $type) {
    $query .= $add . "n.type = '" . $type . "'";
    $add = " or ";
  }
  $query .= ")";
  $result = db_query($query, $gid);
  while ($row = db_fetch_object($result)) {
    if (!in_array($row->nid, $exclude)) {
      $options[$row->nid] = $row->title;
    }
  }
  $selected = array_keys($selected);
  if (count($options)) {
    $type = count($options) >= 20 ? 'select' : 'checkboxes';
    return array(
      '#type' => $type,
      '#title' => $title,
      '#default_value' => $selected,
      '#options' => $options,
      '#description' => '',
      '#multiple' => 1,
      '#size' => min(9, count($options)),
      '#weight' => -1,
    );
  }
  else {
    return "";
  }
}