2 namespace callnotifier;
4 class CallMonitor_Detailler_LDAP implements CallMonitor_Detailler
6 public function __construct($ldapConfig)
8 $this->ldap = \Net_LDAP2::connect($ldapConfig);
9 if (\PEAR::isError($this->ldap)) {
11 'Could not connect to LDAP-server: ' . $this->ldap->getMessage()
16 public function loadCallDetails(CallMonitor_Call $call)
18 if ($call->type == CallMonitor_Call::INCOMING) {
19 $call->fromName = $this->loadName($call->from);
21 $call->toName = $this->loadName($call->to);
25 protected function loadName($number)
27 $filter = \Net_LDAP2_Filter::combine(
30 \Net_LDAP2_Filter::create('companyPhone', 'equals', $number),
31 \Net_LDAP2_Filter::create('homePhone', 'equals', $number),
32 \Net_LDAP2_Filter::create('mobile', 'equals', $number),
33 \Net_LDAP2_Filter::create('otherPhone', 'equals', $number),
34 \Net_LDAP2_Filter::create('telephoneNumber', 'equals', $number),
39 'attributes' => array('displayName', 'givenName', 'sn', 'cn')
42 $search = $this->ldap->search(null, $filter, $options);
43 if (\PEAR::isError($search)) {
45 'Error searching LDAP: ' . $search->getMessage()
48 if ($search->count() == 0) {
52 $arEntry = $search->shiftEntry()->getValues();
53 if (isset($arEntry['displayName'])) {
54 return $arEntry['displayName'];
55 } else if (isset($arEntry['sn']) && $arEntry['givenName']) {
56 return $arEntry['givenName'] . ' ' . $arEntry['sn'];
57 } else if (isset($arEntry['cn'])) {
58 return $arEntry['cn'];