You are here

function oa_subspaces_matching_sections in Open Atrium Subspaces 7.2

Return an array of section ids with the same Name as $section_id

Parameters

$entity entity or entity_id:

1 call to oa_subspaces_matching_sections()
oa_subspaces_views_query_alter in ./oa_subspaces.module
Implements hook_views_query_alter().

File

./oa_subspaces.module, line 363

Code

function oa_subspaces_matching_sections($entity, $groups = array(), $omit_groups = array()) {
  $cache =& drupal_static(__FUNCTION__, array());
  if (is_numeric($entity)) {

    // Get the entity.
    $entity = current(entity_load('node', array(
      $entity,
    )));
  }
  $id = $entity->nid;
  if (isset($cache[$id])) {

    // Return cached values.
    return $cache[$id];
  }
  $cache[$id] = array();
  $query = db_select('node', 'n');
  $query
    ->leftJoin('og_membership', 'f', "n.nid = f.etid");
  if (!empty($groups)) {
    $query
      ->condition('f.gid', $groups, 'IN');
  }
  if (!empty($omit_groups)) {
    $query
      ->condition('f.gid', $omit_groups, 'NOT IN');
  }
  $query
    ->fields('n', array(
    'nid',
  ))
    ->condition('f.entity_type', 'node')
    ->condition('n.status', 1)
    ->condition('n.title', $entity->title)
    ->addTag('node_access');
  $cache[$id] = $query
    ->execute()
    ->fetchCol(0);
  return $cache[$id];
}