You are here

private function LdapUserConfAdmin::addServerMappingFields in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_user/LdapUserConfAdmin.class.php \LdapUserConfAdmin::addServerMappingFields()

add existing mappings to ldap user provisioning mapping admin form table

Parameters

drupal form array $form:

enum $direction LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY:

Return value

by reference to $form array

1 call to LdapUserConfAdmin::addServerMappingFields()
LdapUserConfAdmin::drupalForm in ldap_user/LdapUserConfAdmin.class.php
generate admin form for ldapUserConf object

File

ldap_user/LdapUserConfAdmin.class.php, line 719

Class

LdapUserConfAdmin

Code

private function addServerMappingFields(&$form, $direction) {
  if ($direction == LDAP_USER_PROV_DIRECTION_NONE) {
    return;
  }
  $text = $direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER ? 'target' : 'source';
  $user_attr_options = array(
    '0' => t('Select') . ' ' . $text,
  );
  if (!empty($this->synchMapping[$direction])) {
    foreach ($this->synchMapping[$direction] as $target_id => $mapping) {
      if (!isset($mapping['name']) || isset($mapping['exclude_from_mapping_ui']) && $mapping['exclude_from_mapping_ui']) {
        continue;
      }
      if (isset($mapping['configurable_to_drupal']) && $mapping['configurable_to_drupal'] && $direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER || isset($mapping['configurable_to_ldap']) && $mapping['configurable_to_ldap'] && $direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
        $user_attr_options[$target_id] = substr($mapping['name'], 0, 25);
      }
    }
  }
  $user_attr_options['user_tokens'] = '-- user tokens --';
  $row = 0;

  // 1. non configurable mapping rows
  foreach ($this->synchMapping[$direction] as $target_id => $mapping) {
    if (isset($mapping['exclude_from_mapping_ui']) && $mapping['exclude_from_mapping_ui']) {
      continue;
    }
    if (!$this
      ->isMappingConfigurable($mapping, 'ldap_user') && ($mapping['direction'] == $direction || $mapping['direction'] == LDAP_USER_PROV_DIRECTION_ALL)) {

      // is configurable by ldap_user module (not direction to ldap_user)
      $this
        ->addSynchFormRow($form, 'nonconfigurable', $direction, $mapping, $user_attr_options, $row);
      $row++;
    }
  }

  // 2. existing configurable mappings rows
  if (!empty($this->ldapUserSynchMappings[$direction])) {
    foreach ($this->ldapUserSynchMappings[$direction] as $target_attr_token => $mapping) {

      // key could be ldap attribute name or user attribute name
      if (isset($mapping['enabled']) && $mapping['enabled'] && $this
        ->isMappingConfigurable($this->synchMapping[$direction][$target_attr_token], 'ldap_user')) {
        $this
          ->addSynchFormRow($form, 'update', $direction, $mapping, $user_attr_options, $row);
        $row++;
      }
    }
  }

  // 3. leave 4 rows for adding more mappings
  for ($i = 0; $i < 4; $i++) {
    $this
      ->addSynchFormRow($form, 'add', $direction, NULL, $user_attr_options, $row);
    $row++;
  }
}