function domain_get_user_domains in Domain Access 7.3
Same name and namespace in other branches
- 6.2 domain.module \domain_get_user_domains()
- 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.
Return value
An array of domains to which the user is assigned, in the format array($domain_id => $domain_id).
7 calls to domain_get_user_domains()
- domain_content_check in domain_content/
domain_content.module - Access checking routine for menu and node editing checks.
- domain_form_alter in ./
domain.module - Implements hook_form_alter().
- domain_form_user_form_alter in ./
domain.module - Helper function for the two user forms we care about.
- domain_strict_node_grants_alter in domain_strict/
domain_strict.module - Implements hook_node_access_grants_alter().
- domain_update_users in ./
domain.module - FormsAPI to handle the batch update of users.
File
- ./
domain.module, line 1415 - Core module functions for the Domain Access suite.
Code
function domain_get_user_domains($account, $add_roles = TRUE) {
if (empty($account)) {
// This may happen when creating a new user.
return array();
}
$uid = (int) $account->uid;
$user_domains = array();
$result = db_query("SELECT domain_id FROM {domain_editor} WHERE uid = :uid", array(
':uid' => $uid,
));
foreach ($result as $data) {
$user_domains[$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)) {
// If this role is assigned to "All domains"
if (!empty($filter[DOMAIN_ALL])) {
// Add all active domains to the user
foreach (domain_id_list() as $domain_id) {
$user_domains[$domain_id] = $domain_id;
}
// We don't need to loop anymore, as all roles have already been added.
break;
}
else {
foreach ($filter as $machine_name => $status) {
if ($status && ($domain_id = domain_load_domain_id($machine_name))) {
$user_domains[$domain_id] = $domain_id;
}
}
}
}
}
}
return $user_domains;
}