function ldap_user_is_ldap_associated in Lightweight Directory Access Protocol (LDAP) 8.2
Same name and namespace in other branches
- 7.2 ldap_user/ldap_user.module \ldap_user_is_ldap_associated()
Parameters
stdClass $account as drupal user object:
enum int $direction indicating which directions to test for association: LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER signifies test if drupal account has been provisioned or synched from ldap LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY signifies test if ldap account has been provisioned or synched from drupal NULL signifies check for either direction
Return value
boolean if user is ldap associated
2 calls to ldap_user_is_ldap_associated()
- LdapUserUnitTests::testProvisionToDrupal in ldap_user/
tests/ ldap_user.test - ldap_user_user_presave in ldap_user/
ldap_user.module - Implements hook_user_presave()
File
- ldap_user/
ldap_user.module, line 669 - Module for the LDAP User Entity
Code
function ldap_user_is_ldap_associated($account, $direction = NULL) {
$to_drupal_user = FALSE;
$to_ldap_entry = FALSE;
if ($direction === NULL || $direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
if (property_exists($account, 'ldap_user_current_dn') && !empty($account->ldap_user_current_dn['und'][0]['value'])) {
$to_drupal_user = TRUE;
}
elseif (isset($account->uid)) {
$authmaps = db_query("SELECT aid, uid, module, authname FROM {authmap} WHERE uid = :uid AND module = :module", array(
':uid' => $account->uid,
':module' => 'ldap_user',
))
->fetchAllAssoc('aid', PDO::FETCH_ASSOC);
$to_drupal_user = (bool) count($authmaps);
}
}
if ($direction === NULL || $direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
if (property_exists($account, 'ldap_user_prov_entries') && !empty($account->ldap_user_prov_entries['und'][0]['value'])) {
$to_ldap_entry = TRUE;
}
}
if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
return $to_drupal_user;
}
elseif ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
return $to_ldap_entry;
}
else {
return $to_ldap_entry || $to_drupal_user;
}
}