Ejemplo n.º 1
0
 /**
  * Parse the LDAP search results into a nice array
  *
  * @param resource $searchResult
  * @return array
  */
 protected function parseSearchResult($searchResult)
 {
     $result = array();
     ldap_sort($this->_directoryServer, $searchResult, $this->_controller->getConfig()->getLdapFirstNameAttribute());
     ldap_sort($this->_directoryServer, $searchResult, $this->_controller->getConfig()->getLdapLastNameAttribute());
     if (ldap_count_entries($this->_directoryServer, $searchResult)) {
         $entries = ldap_get_entries($this->_directoryServer, $searchResult);
         for ($i = 0; $i < $entries["count"]; $i++) {
             $arr = array('userName' => '', 'firstName' => '', 'lastName' => '', 'emailAddress' => '');
             if (!empty($entries[$i][strtolower($this->_controller->getConfig()->getLdapUsernameAttribute())][0])) {
                 $arr['userName'] = $entries[$i][strtolower($this->_controller->getConfig()->getLdapUsernameAttribute())][0];
             }
             if (!empty($entries[$i][strtolower($this->_controller->getConfig()->getLdapFirstNameAttribute())][0])) {
                 $arr['firstName'] = $entries[$i][strtolower($this->_controller->getConfig()->getLdapFirstNameAttribute())][0];
             }
             if (!empty($entries[$i][strtolower($this->_controller->getConfig()->getLdapLastNameAttribute())][0])) {
                 $arr['lastName'] = $entries[$i][strtolower($this->_controller->getConfig()->getLdapLastNameAttribute())][0];
             }
             if (!empty($entries[$i][strtolower($this->_controller->getConfig()->getLdapEmailAddressAttribute())][0])) {
                 $arr['emailAddress'] = $entries[$i][strtolower($this->_controller->getConfig()->getLdapEmailAddressAttribute())][0];
             }
             $result[] = $arr;
         }
     }
     return $result;
 }