Changeset View
Changeset View
Standalone View
Standalone View
plugins/kolab_addressbook/drivers/kolab/kolab_contacts.php
Show First 20 Lines • Show All 379 Lines • ▼ Show 20 Lines | public function list_records($cols = null, $subset = 0, $nocount = false) | ||||
} | } | ||||
// get members by UID | // get members by UID | ||||
if (!empty($uids)) { | if (!empty($uids)) { | ||||
$this->_fetch_contacts($query = array(array('uid', '=', $uids)), $fetch_all ? false : count($uids), $fast_mode); | $this->_fetch_contacts($query = array(array('uid', '=', $uids)), $fetch_all ? false : count($uids), $fast_mode); | ||||
$this->sortindex = array_merge($this->sortindex, $local_sortindex); | $this->sortindex = array_merge($this->sortindex, $local_sortindex); | ||||
} | } | ||||
} | } | ||||
else if (is_array($this->filter['ids'])) { | else if ($this->filter && is_array($this->filter['ids'])) { | ||||
$ids = $this->filter['ids']; | $ids = $this->filter['ids']; | ||||
if (count($ids)) { | if (count($ids)) { | ||||
$uids = array_map(array($this, 'id2uid'), $this->filter['ids']); | $uids = array_map(array($this, 'id2uid'), $this->filter['ids']); | ||||
$this->_fetch_contacts($query = array(array('uid', '=', $uids)), count($ids), $fast_mode); | $this->_fetch_contacts($query = array(array('uid', '=', $uids)), count($ids), $fast_mode); | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
$this->_fetch_contacts($query = 'contact', true, $fast_mode); | $this->_fetch_contacts($query = 'contact', true, $fast_mode); | ||||
▲ Show 20 Lines • Show All 732 Lines • ▼ Show 20 Lines | |||||
* Extract a string for sorting from the given contact record | * Extract a string for sorting from the given contact record | ||||
*/ | */ | ||||
private function _sort_string($rec) | private function _sort_string($rec) | ||||
{ | { | ||||
$str = ''; | $str = ''; | ||||
switch ($this->sort_col) { | switch ($this->sort_col) { | ||||
case 'name': | case 'name': | ||||
$str = $rec['name'] . $rec['prefix']; | $str = ($rec['name'] ?? null) . ($rec['prefix'] ?? null); | ||||
case 'firstname': | case 'firstname': | ||||
$str .= $rec['firstname'] . $rec['middlename'] . $rec['surname']; | $str .= ($rec['firstname'] ?? null) . ($rec['middlename'] ?? null) . ($rec['surname'] ?? null); | ||||
break; | break; | ||||
case 'surname': | case 'surname': | ||||
$str = $rec['surname'] . $rec['firstname'] . $rec['middlename']; | $str = ($rec['surname'] ?? null) . ($rec['firstname'] ?? null) . ($rec['middlename'] ?? null); | ||||
break; | break; | ||||
default: | default: | ||||
$str = $rec[$this->sort_col]; | $str = $rec[$this->sort_col]; | ||||
break; | break; | ||||
} | } | ||||
if ($rec['email'] ?? null) { | |||||
$str .= is_array($rec['email']) ? $rec['email'][0] : $rec['email']; | $str .= is_array($rec['email']) ? $rec['email'][0] : $rec['email']; | ||||
} | |||||
return mb_strtolower($str); | return mb_strtolower($str); | ||||
} | } | ||||
/** | /** | ||||
* Return the cache table columns to order by | * Return the cache table columns to order by | ||||
*/ | */ | ||||
private function _sort_columns() | private function _sort_columns() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | |||||
* Map fields from internal Kolab_Format to Roundcube contact format | * Map fields from internal Kolab_Format to Roundcube contact format | ||||
*/ | */ | ||||
private function _to_rcube_contact($record) | private function _to_rcube_contact($record) | ||||
{ | { | ||||
$record['ID'] = $this->uid2id($record['uid']); | $record['ID'] = $this->uid2id($record['uid']); | ||||
// convert email, website, phone values | // convert email, website, phone values | ||||
foreach (array('email'=>'address', 'website'=>'url', 'phone'=>'number') as $col => $propname) { | foreach (array('email'=>'address', 'website'=>'url', 'phone'=>'number') as $col => $propname) { | ||||
if (is_array($record[$col])) { | if (is_array($record[$col] ?? null)) { | ||||
$values = $record[$col]; | $values = $record[$col]; | ||||
unset($record[$col]); | unset($record[$col]); | ||||
foreach ((array)$values as $i => $val) { | foreach ((array)$values as $i => $val) { | ||||
$key = $col . ($val['type'] ? ':' . $val['type'] : ''); | $key = $col . ($val['type'] ? ':' . $val['type'] : ''); | ||||
$record[$key][] = $val[$propname]; | $record[$key][] = $val[$propname]; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (is_array($record['address'])) { | if (is_array($record['address'] ?? null)) { | ||||
$addresses = $record['address']; | $addresses = $record['address']; | ||||
unset($record['address']); | unset($record['address']); | ||||
foreach ($addresses as $i => $adr) { | foreach ($addresses as $i => $adr) { | ||||
$key = 'address' . ($adr['type'] ? ':' . $adr['type'] : ''); | $key = 'address' . ($adr['type'] ? ':' . $adr['type'] : ''); | ||||
$record[$key][] = array( | $record[$key][] = array( | ||||
'street' => $adr['street'], | 'street' => $adr['street'], | ||||
'locality' => $adr['locality'], | 'locality' => $adr['locality'], | ||||
'zipcode' => $adr['code'], | 'zipcode' => $adr['code'], | ||||
'region' => $adr['region'], | 'region' => $adr['region'], | ||||
'country' => $adr['country'], | 'country' => $adr['country'], | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
// photo is stored as separate attachment | // photo is stored as separate attachment | ||||
if ($record['photo'] && strlen($record['photo']) < 255 && !empty($record['_attachments'][$record['photo']])) { | if (($record['photo'] ?? null) && strlen($record['photo']) < 255 && !empty($record['_attachments'][$record['photo']])) { | ||||
$att = $record['_attachments'][$record['photo']]; | $att = $record['_attachments'][$record['photo']]; | ||||
// only fetch photo content if requested | // only fetch photo content if requested | ||||
if ($this->action == 'photo') { | if ($this->action == 'photo') { | ||||
if (!empty($att['content'])) { | if (!empty($att['content'])) { | ||||
$record['photo'] = $att['content']; | $record['photo'] = $att['content']; | ||||
} | } | ||||
else { | else { | ||||
$record['photo'] = $this->storagefolder->get_attachment($record['uid'], $att['id']); | $record['photo'] = $this->storagefolder->get_attachment($record['uid'], $att['id']); | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |