You are here

function ldap_user_is_ldap_associated in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_user/ldap_user.module \ldap_user_is_ldap_associated()

Parameters

object $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 702
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[LANGUAGE_NONE][0]['value'])) {
      $to_drupal_user = TRUE;
    }
    elseif (isset($account->uid)) {
      $authname = ldap_user_get_authname($account);
      $to_drupal_user = (bool) $authname;
    }
  }
  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[LANGUAGE_NONE][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;
  }
}