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 $call->fromName = $this->loadName($call->from);
48 $call->toName = $this->loadName($call->to);
52 protected function loadName($number)
54 $filter = \Net_LDAP2_Filter::combine(
57 \Net_LDAP2_Filter::create('companyPhone', 'equals', $number),
58 \Net_LDAP2_Filter::create('homePhone', 'equals', $number),
59 \Net_LDAP2_Filter::create('mobile', 'equals', $number),
60 \Net_LDAP2_Filter::create('otherPhone', 'equals', $number),
61 \Net_LDAP2_Filter::create('telephoneNumber', 'equals', $number),
66 'attributes' => array('displayName', 'givenName', 'sn', 'cn')
69 $search = $this->ldap->search(null, $filter, $options);
70 if (\PEAR::isError($search)) {
72 'Error searching LDAP: ' . $search->getMessage()
75 if ($search->count() == 0) {
79 $arEntry = $search->shiftEntry()->getValues();
80 if (isset($arEntry['displayName'])) {
81 return $arEntry['displayName'];
82 } else if (isset($arEntry['sn']) && $arEntry['givenName']) {
83 return $arEntry['givenName'] . ' ' . $arEntry['sn'];
84 } else if (isset($arEntry['cn'])) {
85 return $arEntry['cn'];