You are here

class FeedsDrupalUserLdapEntryFetcherResult in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_feeds/FeedsDrupalUserLdapEntryFetcher.inc \FeedsDrupalUserLdapEntryFetcherResult
  2. 7 ldap_feeds/FeedsDrupalUserLdapEntryFetcher.inc \FeedsDrupalUserLdapEntryFetcherResult

Hierarchy

Expanded class hierarchy of FeedsDrupalUserLdapEntryFetcherResult

File

ldap_feeds/FeedsDrupalUserLdapEntryFetcher.inc, line 13
FeedsDrupalUserLdapEntryFetcher.

View source
class FeedsDrupalUserLdapEntryFetcherResult extends FeedsFetcherResult {
  public $filterLdapAuthenticated;
  public $availableDrupalUserAttributes;
  public $filterRoles;

  /**
   * Constructor.
   */
  public function __construct($source_config) {
    $this->availableDrupalUserAttributes = ldap_feeds_drupal_user_attributes();
    $this->filterLdapAuthenticated = isset($source_config['filterLdapAuthenticated']) ? $source_config['filterLdapAuthenticated'] : LDAP_FEEDS_DRUPAL_USER_FETCHER_FILTER_AUTHENTICATED;
    $this->filterRoles = isset($source_config['filterRoles']) ? $source_config['filterRoles'] : LDAP_FEEDS_DRUPAL_USER_FETCHER_FILTER_ROLES;
    parent::__construct('');
    $this->ldap_result = $this
      ->getRaw();
    return $this->ldap_result;
  }

  /**
   * Overrides parent::getRaw();.
   */
  public function getRaw() {

    // Needs to loop through all users, and query ldap for each, one at a time.
    $query = new EntityFieldQuery();
    $entities = $query
      ->entityCondition('entity_type', 'user')
      ->execute();
    $users = entity_load('user', array_keys($entities['user']));
    if ($this->filterRoles) {
      $selectedRoles = array_filter($this->filterRoles);
      $filterOnRoles = (bool) count($selectedRoles);
    }
    else {
      $filterOnRoles = FALSE;
    }
    foreach ($users as $uid => $user) {
      if ($uid == 0 || $uid == 1 || $this->filterLdapAuthenticated && !isset($user->data['ldap_user']) || $filterOnRoles && !array_intersect(array_values($selectedRoles), array_keys($user->roles))) {
        continue;
      }
      if ($ldap_user = ldap_servers_get_user_ldap_data($user)) {
        unset($ldap_user['mail']);
        $ldap_user['attr']['count'] = $ldap_user['attr']['count'] + count($this->availableDrupalUserAttributes);
        foreach ($this->availableDrupalUserAttributes as $attr_name => $attr_conf) {
          $ldap_user['attr'][] = $attr_conf['token'];
          $ldap_user['attr'][$attr_conf['token']]['count'] = 1;
          $ldap_user['attr'][$attr_conf['token']][0] = (string) $user->{$attr_name};
        }
        $results[] = $ldap_user;
      }
    }
    $results['count'] = count($results);
    return $results;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedsDrupalUserLdapEntryFetcherResult::$availableDrupalUserAttributes public property
FeedsDrupalUserLdapEntryFetcherResult::$filterLdapAuthenticated public property
FeedsDrupalUserLdapEntryFetcherResult::$filterRoles public property
FeedsDrupalUserLdapEntryFetcherResult::getRaw public function Overrides parent::getRaw();. Overrides FeedsFetcherResult::getRaw
FeedsDrupalUserLdapEntryFetcherResult::__construct public function Constructor. Overrides FeedsFetcherResult::__construct
FeedsFetcherResult::$file_path protected property The path to a file where the raw data is stored.
FeedsFetcherResult::$raw protected property The raw fetched data.
FeedsFetcherResult::checkFile protected function Checks that a file exists and is readable.
FeedsFetcherResult::constructFilePath public function Constructs file name for saving the raw data.
FeedsFetcherResult::fileExists public function Returns if the file to parse exists.
FeedsFetcherResult::getFeedsInProgressDir public function Returns directory for storing files that are in progress of import.
FeedsFetcherResult::getFileContents public function Returns the contents of a file, if it exists.
FeedsFetcherResult::getFilePath public function Get a path to a temporary file containing the resource provided by the fetcher. 1
FeedsFetcherResult::rawExists public function Returns if raw data exists.
FeedsFetcherResult::sanitizeFile public function Sanitize the file in place.
FeedsFetcherResult::sanitizeRaw public function Sanitize the raw content string.
FeedsFetcherResult::sanitizeRawOptimized public function Sanitize the raw content string.
FeedsFetcherResult::saveRawToFile public function Saves the raw fetcher result to a file.
FeedsFetcherResult::__sleep public function Prevent saving the raw result when serializing object.