You are here

public function SyncMappingHelper::getSyncMappings in Lightweight Directory Access Protocol (LDAP) 8.3

Util to fetch mappings for a given direction.

Parameters

string $direction: Direction to sync in.

array $prov_events: Events to act upon.

Return value

array|bool Array of mappings (may be empty array)

1 call to SyncMappingHelper::getSyncMappings()
SyncMappingHelper::getLdapUserRequiredAttributes in ldap_user/src/Helper/SyncMappingHelper.php
Util to fetch attributes required for this user conf, not other modules.

File

ldap_user/src/Helper/SyncMappingHelper.php, line 90

Class

SyncMappingHelper
Helper class to process user field synchronisation mappings.

Namespace

Drupal\ldap_user\Helper

Code

public function getSyncMappings($direction = NULL, array $prov_events = NULL) {
  if (!$prov_events) {
    $prov_events = LdapConfiguration::getAllEvents();
  }
  if ($direction == NULL) {
    $direction = self::PROVISION_TO_ALL;
  }
  $mappings = [];
  if ($direction == self::PROVISION_TO_ALL) {
    $directions = [
      self::PROVISION_TO_DRUPAL,
      self::PROVISION_TO_LDAP,
    ];
  }
  else {
    $directions = [
      $direction,
    ];
  }

  // TODO: Note that we again query the DB, getSyncMappings() goes around the
  // general implementation and could be its own class.
  foreach ($directions as $direction) {
    if (!empty($this->config
      ->get('ldapUserSyncMappings')[$direction])) {
      foreach ($this->config
        ->get('ldapUserSyncMappings')[$direction] as $mapping) {
        if (!empty($mapping['prov_events'])) {
          $result = count(array_intersect($prov_events, $mapping['prov_events']));
          if ($result) {
            if ($direction == self::PROVISION_TO_DRUPAL && isset($mapping['user_attr'])) {
              $key = $mapping['user_attr'];
            }
            elseif ($direction == self::PROVISION_TO_LDAP && isset($mapping['ldap_attr'])) {
              $key = $mapping['ldap_attr'];
            }
            else {
              continue;
            }
            $mappings[$key] = $mapping;
          }
        }
      }
    }
  }
  return $mappings;
}