You are here

function oa_teams_get_teams_for_space in Open Atrium Core 7.2

Get the listing of teams that are in the specified space, or the current space is no space is specified.

Parameters

int $gid: (Optional) The space ID. Defaults to the current Space.

bool $include_inherited: (Optional) If set to TRUE (the default), teams from Spaces that this Space inherits members from will be included as well.

Return value

array An associative array with the nid of each team as the key, and an object as the value with the following properties:

  • nid
  • title
5 calls to oa_teams_get_teams_for_space()
OaTeams_SelectionHandler::getReferencableEntities in modules/oa_teams/plugins/entityreference_selection/OaTeams_SelectionHandler.class.php
Implements EntityReferenceHandler::getReferencableEntities().
oa_access_team_permissions_form in modules/oa_access/oa_access.admin.inc
Form constructor for the Team permissions form.
oa_access_user_teams in modules/oa_access/oa_access.module
Get a list of this user's Teams.
oa_core_members_widget_render in plugins/content_types/oa_core_members_widget.inc
Main render function for oa_core_members_widget.
_oa_access_is_overridden in modules/oa_access/oa_access.module
Helper function to determine if a permission is overridden by Group or Team.

File

modules/oa_teams/oa_teams.module, line 70

Code

function oa_teams_get_teams_for_space($gid = NULL, $include_inherited = TRUE) {
  if (!isset($gid)) {
    $gid = oa_core_get_space_context();
  }
  if (!$gid) {
    return array();
  }
  $query = db_select('node', 'n');
  $query
    ->rightJoin('og_membership', 'og', 'n.nid = og.etid');
  $query
    ->fields('n', array(
    'nid',
    'title',
  ))
    ->condition('n.type', OA_TEAM_TYPE)
    ->condition('og.entity_type', 'node')
    ->condition('og.field_name', OA_SPACE_FIELD)
    ->condition('og.gid', $gid)
    ->addTag('node_access');
  $result = $query
    ->execute()
    ->fetchAllAssoc('nid');
  if ($include_inherited) {

    // Gets all parents, not just direct ones, so we need to pass FALSE for
    // $include_inherited to prevent it from checking the same parents multiple
    // times.
    $parents = og_subgroups_parents_load('node', $gid);
    foreach ($parents as $parent_type => $parent_id) {
      $result = $result + oa_teams_get_teams_for_space($parent_id, FALSE);
    }
  }
  return $result;
}