domain_get_user_domains($account, $add_roles = TRUE, $reset = FALSE)Get the domains a user is assigned to.
$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.
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.
./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];
}
?>