Commit 22cc34db5be7bc3a94347b9a9e4f5b5fa9ee6e2b
1 parent
f5704b0e
Add an example of how to synchronise a field's lookups with an external
source (LDAP in this case). (Requires Net/LDAP from PEAR) git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4008 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
43 additions
and
0 deletions
examples/fieldsynchronisation/syncFieldFromLDAP.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once('../../config/dmsDefaults.php'); | |
| 4 | + | |
| 5 | +require_once('Net/LDAP.php'); | |
| 6 | +require_once(KT_LIB_DIR . '/metadata/metadatautil.inc.php'); | |
| 7 | + | |
| 8 | +$oKTConfig =& KTConfig::getSingleton(); | |
| 9 | + | |
| 10 | +$config = array( | |
| 11 | + 'dn' => $oKTConfig->get("ldap/ldapSearchUser"), | |
| 12 | + 'password' => $oKTConfig->get("ldap/ldapSearchPassword"), | |
| 13 | + 'host' => $oKTConfig->get("ldap/ldapServer"), | |
| 14 | + 'base' => $oKTConfig->get("ldap/ldapRootDn"), | |
| 15 | +); | |
| 16 | + | |
| 17 | +$oFieldset =& KTFieldset::getByNamespace('http://ktcvs.local/local/fieldsets/synctest'); | |
| 18 | +$oField = DocumentField::getByFieldsetAndName($oFieldset, 'synctest'); | |
| 19 | + | |
| 20 | +$oLdap =& Net_LDAP::connect($config); | |
| 21 | +if (PEAR::isError($oLdap)) { | |
| 22 | + var_dump($oLdap); | |
| 23 | + exit(0); | |
| 24 | +} | |
| 25 | + | |
| 26 | +$aParams = array( | |
| 27 | + 'scope' => 'sub', | |
| 28 | + 'attributes' => array('cn'), | |
| 29 | +); | |
| 30 | +$rootDn = $oKTConfig->get("ldap/ldapRootDn"); | |
| 31 | +if (is_array($rootDn)) { | |
| 32 | + $rootDn = join(",", $rootDn); | |
| 33 | +} | |
| 34 | +$aResults = $oLdap->search($rootDn, '(objectClass=organizationalPerson)', $aParams); | |
| 35 | + | |
| 36 | +$aValues = array(); | |
| 37 | +foreach ($aResults->entries() as $oEntry) { | |
| 38 | + // print $oEntry->dn() . "\n"; | |
| 39 | + $sValue = $oEntry->get_value('cn', 'single'); | |
| 40 | + // print $sValue . "\n"; | |
| 41 | + $aValues[] = $sValue; | |
| 42 | +} | |
| 43 | +KTMetadataUtil::synchroniseMetadata($oField, $aValues); | ... | ... |