You are here

function domain_get_user_domains in Domain Access 6.2

Same name and namespace in other branches
  1. 7.3 domain.module \domain_get_user_domains()
  2. 7.2 domain.module \domain_get_user_domains()

Get the domains a user is assigned to.

Parameters

$account: The user account object.

$add_roles: A boolean flag indicating whether to add the default role settings to the user's domains.

$reset: A boolean flag indicating whether to reset the static array or not.

Return value

An array of domains to which the user is assigned, in the format array($domain_id => $domain_id). Note that the default domain is -1 here, due to checkbox behavior.

10 calls to domain_get_user_domains()
domain_boot in ./domain.module
Module setup tasks.
domain_content_check in domain_content/domain_content.module
Access checking routine for menu and node editing checks.
domain_form_alter in ./domain.module
Implement hook_form_alter()
domain_node_grants in ./domain.module
Implement hook_node_grants.
domain_source_form_alter in domain_source/domain_source.module
Implement hook_form_alter()

... See full list

File

./domain.module, line 1110
Core module functions for the Domain Access suite.

Code

function domain_get_user_domains($account, $add_roles = TRUE, $reset = FALSE) {
  static $domains = array();
  if (empty($account)) {

    // This may happen when creating a new user.
    return array();
  }
  $uid = (int) $account->uid;
  if (!isset($domains[$uid]) || $reset) {
    $domains[$uid] = array();
    $result = db_query("SELECT domain_id FROM {domain_editor} WHERE uid = %d", $uid);
    while ($data = db_fetch_object($result)) {
      if ($data->domain_id == 0) {
        $domains[$uid]['-1'] = -1;
      }
      else {
        $domains[$uid][$data->domain_id] = $data->domain_id;
      }
    }
    if ($add_roles) {
      if (empty($account->roles)) {
        $account->roles = array(
          0 => 'new user',
        );
      }

      // Add the role-based additions.
      $defaults = variable_get('domain_roles', array());
      foreach ($account->roles as $rid => $role) {
        $filter = array();
        if (isset($defaults[$rid])) {
          $filter = array_filter($defaults[$rid]);
        }
        if (!empty($filter)) {
          foreach ($filter as $domain_id => $status) {
            if ($status) {
              $domains[$uid][$domain_id] = $domain_id;
            }
          }
        }
      }
    }
  }
  return $domains[$uid];
}