You are here

function oa_access_user_groups in Open Atrium Core 7.2

Get a list of this user's Groups.

Parameters

object $account: (Optional) The user to get groups for. If NULL, it will find groups for the currently logged in user.

Return value

array An array of Group nids.

2 calls to oa_access_user_groups()
oa_access in modules/oa_access/oa_access.module
Determines if the user has a permission.
OpenAtriumAccessTestCase::testUserGroups in modules/oa_access/tests/oa_access.test

File

modules/oa_access/oa_access.module, line 327
Code for the Open Atrium Access module.

Code

function oa_access_user_groups($account = NULL) {
  global $user;
  if (is_null($account)) {
    $account = $user;
  }
  $cache =& drupal_static(__FUNCTION__, array());
  if (!isset($cache[$account->uid])) {

    // First, get all the users oa_groups.
    $query = db_select('og_membership', 'og');
    $query
      ->innerJoin('node', 'n', 'og.gid = n.nid');
    $query
      ->fields('n', array(
      'nid',
      'type',
    ))
      ->condition('og.group_type', 'node')
      ->condition('og.entity_type', 'user')
      ->condition('og.state', OG_STATE_ACTIVE)
      ->condition('n.type', 'oa_group')
      ->condition('og.etid', $account->uid);
    $groups = array();
    foreach ($query
      ->execute() as $row) {
      $groups[$row->nid] = $row->nid;
    }

    // All users are members of the magic 'All' group with an NID of 0.
    $groups[0] = 0;
    $cache[$account->uid] = $groups;
  }
  return $cache[$account->uid];
}