From 22cc34db5be7bc3a94347b9a9e4f5b5fa9ee6e2b Mon Sep 17 00:00:00 2001 From: Neil Blakey-Milner Date: Wed, 16 Nov 2005 14:38:25 +0000 Subject: [PATCH] Add an example of how to synchronise a field's lookups with an external source (LDAP in this case). --- examples/fieldsynchronisation/syncFieldFromLDAP.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+), 0 deletions(-) create mode 100644 examples/fieldsynchronisation/syncFieldFromLDAP.php 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); -- libgit2 0.21.4