2 namespace callnotifier;
5 * Fetch caller names from a LDAP address book.
7 * The following attributes are searched:
14 * For the first result, the displayName is used if defined.
15 * If it does not exist, the givenName + sn are used.
17 * Set "toName" or "fromName", depending on call type.
19 * Uses the Net_LDAP2 PEAR package
21 class CallMonitor_Detailler_LDAP implements CallMonitor_Detailler
24 * Create new ldap name resolver
26 * @param array $ldapConfig Array of Net_LDAP2 configuration parameters.
27 * Some of those you might want to use:
28 * - host - LDAP server host name
29 * - basedn - root DN that gets searched
30 * - binddn - Username to authenticate with
31 * - bindpw - Password for username
33 public function __construct($ldapConfig)
35 $this->ldap = \Net_LDAP2::connect($ldapConfig);
36 if (\PEAR::isError($this->ldap)) {
38 'Could not connect to LDAP-server: ' . $this->ldap->getMessage()
43 public function loadCallDetails(CallMonitor_Call $call)
45 if ($call->type == CallMonitor_Call::INCOMING) {
46 if (!isset($call->fromName) || $call->fromName === null) {
47 $call->fromName = $this->loadName($call->from);
50 if (!isset($call->toName) || $call->toName === null) {
51 $call->toName = $this->loadName($call->to);
56 protected function loadName($number)
58 $filter = \Net_LDAP2_Filter::combine(
61 \Net_LDAP2_Filter::create('companyPhone', 'equals', $number),
62 \Net_LDAP2_Filter::create('homePhone', 'equals', $number),
63 \Net_LDAP2_Filter::create('mobile', 'equals', $number),
64 \Net_LDAP2_Filter::create('otherPhone', 'equals', $number),
65 \Net_LDAP2_Filter::create('telephoneNumber', 'equals', $number),
70 'attributes' => array('displayName', 'givenName', 'sn', 'cn')
73 $search = $this->ldap->search(null, $filter, $options);
74 if (\PEAR::isError($search)) {
76 'Error searching LDAP: ' . $search->getMessage()
79 if ($search->count() == 0) {
83 $arEntry = $search->shiftEntry()->getValues();
84 if (isset($arEntry['displayName'])) {
85 return $arEntry['displayName'];
86 } else if (isset($arEntry['sn']) && $arEntry['givenName']) {
87 return $arEntry['givenName'] . ' ' . $arEntry['sn'];
88 } else if (isset($arEntry['cn'])) {
89 return $arEntry['cn'];