You are here

public function FeedsLdapEntryParser::parse in Lightweight Directory Access Protocol (LDAP) 7

Same name and namespace in other branches
  1. 8.2 ldap_feeds/FeedsLdapEntryParser.inc \FeedsLdapEntryParser::parse()
  2. 7.2 ldap_feeds/FeedsLdapEntryParser.inc \FeedsLdapEntryParser::parse()

Implements FeedsParser::parse().

File

ldap_feeds/FeedsLdapEntryParser.inc, line 15
Provides the Parser for an ldap entry array.

Class

FeedsLdapEntryParser
@file

Code

public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
  $mappings = feeds_importer($this->id)->processor->config['mappings'];
  $ldap_entries = $fetcher_result->ldap_result;
  $parsed_items = array();
  for ($i = 0; $i < $ldap_entries['count']; $i++) {
    $ldap_entry = $ldap_entries[$i];
    $parsed_item = array(
      'dn' => (string) $ldap_entry['dn'],
    );
    foreach ($mappings as $j => $map) {
      $source = $map['source'];
      if (isset($ldap_entry['attr'])) {

        // exception need because of unconvential format of ldap data returned from $ldap_server->user_lookup
        $ldap_attributes = $ldap_entry['attr'];
      }
      else {
        $ldap_attributes = $ldap_entry;
      }
      if ($source != 'dn' && isset($ldap_attributes[$source][0])) {
        if ($ldap_attributes[$source]['count'] == 1 && is_scalar($ldap_attributes[$source][0])) {
          $parsed_item[$source] = (string) $ldap_attributes[$source][0];
        }

        /** removed until design decisions on multivalued attributes are made
                  elseif ($ldap_entry['count'] > 1) {
                    switch ($this->config['multivalued']) {
                      case LDAP_FEEDS_QUERY_FETCHER_MULTI_COMMA:
                        unset($ldap_entry[$source]['count']);
                        $parsed_item[$source] = join(',', $ldap_entry[$source]);
                        break;
                      case LDAP_FEEDS_QUERY_FETCHER_MULTI_SHOW_FIRST:
                        $parsed_item[$source] = $ldap_entry[$source][0];
                        break;

                      case LDAP_FEEDS_QUERY_FETCHER_MULTI_IGNORE:
                        break;

                      case LDAP_FEEDS_QUERY_FETCHER_MULTI_ARRAY:
                        for ($k = 0; $k < $ldap_entry[$source]['count'] - 1; $k++) {
                         if (is_scalar($ldap_entry[$source][$k])) {
                            $parsed_item[$source . '[' . $k . ']'] = (string)$ldap_entry[$source][$k];
                          }
                        }
                    }
                  }
         */
      }
    }
    $parsed_items[] = $parsed_item;
  }
  $result = new FeedsParserResult();
  $result->items = $parsed_items;
  return $result;
}