diff --git a/examples/fieldsynchronisation/syncFieldFromLDAP.php b/examples/fieldsynchronisation/syncFieldFromLDAP.php new file mode 100644 index 0000000..57aae7a --- /dev/null +++ b/examples/fieldsynchronisation/syncFieldFromLDAP.php @@ -0,0 +1,43 @@ + $oKTConfig->get("ldap/ldapSearchUser"), + 'password' => $oKTConfig->get("ldap/ldapSearchPassword"), + 'host' => $oKTConfig->get("ldap/ldapServer"), + 'base' => $oKTConfig->get("ldap/ldapRootDn"), +); + +$oFieldset =& KTFieldset::getByNamespace('http://ktcvs.local/local/fieldsets/synctest'); +$oField = DocumentField::getByFieldsetAndName($oFieldset, 'synctest'); + +$oLdap =& Net_LDAP::connect($config); +if (PEAR::isError($oLdap)) { + var_dump($oLdap); + exit(0); +} + +$aParams = array( + 'scope' => 'sub', + 'attributes' => array('cn'), +); +$rootDn = $oKTConfig->get("ldap/ldapRootDn"); +if (is_array($rootDn)) { + $rootDn = join(",", $rootDn); +} +$aResults = $oLdap->search($rootDn, '(objectClass=organizationalPerson)', $aParams); + +$aValues = array(); +foreach ($aResults->entries() as $oEntry) { + // print $oEntry->dn() . "\n"; + $sValue = $oEntry->get_value('cn', 'single'); + // print $sValue . "\n"; + $aValues[] = $sValue; +} +KTMetadataUtil::synchroniseMetadata($oField, $aValues);