domain_get_user_domains

Versions
domain
domain_get_user_domains($account, $add_roles = TRUE, $reset = FALSE)

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.

▾ 9 functions call domain_get_user_domains()

domain_boot in ./domain.module
Adds the domain user data to the $user object.
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()
domain_strict_domaingrants in domain_strict/domain_strict.module
Implement hook_domaingrants()
domain_user in ./domain.module
Implement hook_user()
domain_views_access in domain_views/domain_views.module
Access callback for use with domain_views_plugin_access.
_domain_user_list in ./domain.module
Helper function to get the names of all domains for a user.

Code

./domain.module, line 885

<?php
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];
}
?>

Contact

  • agentrickard [at] gmail [dot] com

Donations

My Amazon.com Wish List