Adapt libkolab and kolab_addressbook to support type parameters for email addresses
This commit is contained in:
parent
0455116281
commit
02fc214d00
2 changed files with 55 additions and 44 deletions
|
@ -44,7 +44,7 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
'jobtitle' => array('limit' => 1),
|
||||
'organization' => array('limit' => 1),
|
||||
'department' => array('limit' => 1),
|
||||
'email' => array('subtypes' => null),
|
||||
'email' => array('subtypes' => array('home','work','other')),
|
||||
'phone' => array(),
|
||||
'address' => array('subtypes' => array('home','work','office')),
|
||||
'website' => array('subtypes' => array('homepage','blog')),
|
||||
|
@ -1035,21 +1035,15 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
{
|
||||
$record['ID'] = $this->_uid2id($record['uid']);
|
||||
|
||||
if (is_array($record['phone'])) {
|
||||
$phones = $record['phone'];
|
||||
unset($record['phone']);
|
||||
foreach ((array)$phones as $i => $phone) {
|
||||
$key = 'phone' . ($phone['type'] ? ':' . $phone['type'] : '');
|
||||
$record[$key][] = $phone['number'];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($record['website'])) {
|
||||
$urls = $record['website'];
|
||||
unset($record['website']);
|
||||
foreach ((array)$urls as $i => $url) {
|
||||
$key = 'website' . ($url['type'] ? ':' . $url['type'] : '');
|
||||
$record[$key][] = $url['url'];
|
||||
// convert email, website, phone values
|
||||
foreach (array('email'=>'address', 'website'=>'url', 'phone'=>'number') as $col => $propname) {
|
||||
if (is_array($record[$col])) {
|
||||
$values = $record[$col];
|
||||
unset($record[$col]);
|
||||
foreach ((array)$values as $i => $val) {
|
||||
$key = $col . ($val['type'] ? ':' . $val['type'] : '');
|
||||
$record[$key][] = $val[$propname];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1093,31 +1087,22 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
else if (!$contact['uid'] && $old['uid'])
|
||||
$contact['uid'] = $old['uid'];
|
||||
|
||||
$contact['email'] = array_filter($this->get_col_values('email', $contact, true));
|
||||
$contact['im'] = array_filter($this->get_col_values('im', $contact, true));
|
||||
|
||||
$websites = array();
|
||||
$phones = array();
|
||||
// convert email, website, phone values
|
||||
foreach (array('email'=>'address', 'website'=>'url', 'phone'=>'number') as $col => $propname) {
|
||||
$contact[$col] = array();
|
||||
foreach ($this->get_col_values($col, $contact) as $type => $values) {
|
||||
foreach ((array)$values as $val) {
|
||||
if (!empty($val)) {
|
||||
$contact[$col][] = array($propname => $val, 'type' => $type);
|
||||
}
|
||||
}
|
||||
unset($contact[$col.':'.$type]);
|
||||
}
|
||||
}
|
||||
|
||||
$addresses = array();
|
||||
|
||||
foreach ($this->get_col_values('website', $contact) as $type => $values) {
|
||||
foreach ((array)$values as $url) {
|
||||
if (!empty($url)) {
|
||||
$websites[] = array('url' => $url, 'type' => $type);
|
||||
}
|
||||
}
|
||||
unset($contact['website:'.$type]);
|
||||
}
|
||||
|
||||
foreach ($this->get_col_values('phone', $contact) as $type => $values) {
|
||||
foreach ((array)$values as $phone) {
|
||||
if (!empty($phone)) {
|
||||
$phones[] = array('number' => $phone, 'type' => $type);
|
||||
}
|
||||
}
|
||||
unset($contact['phone:'.$type]);
|
||||
}
|
||||
|
||||
foreach ($this->get_col_values('address', $contact) as $type => $values) {
|
||||
foreach ((array)$values as $adr) {
|
||||
// skip empty address
|
||||
|
@ -1138,8 +1123,6 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
unset($contact['address:'.$type]);
|
||||
}
|
||||
|
||||
$contact['website'] = $websites;
|
||||
$contact['phone'] = $phones;
|
||||
$contact['address'] = $addresses;
|
||||
|
||||
// copy meta data (starting with _) from old object
|
||||
|
|
|
@ -47,6 +47,12 @@ class kolab_format_contact extends kolab_format
|
|||
'other' => Telephone::Textphone,
|
||||
);
|
||||
|
||||
public $emailtypes = array(
|
||||
'home' => Email::Home,
|
||||
'work' => Email::Work,
|
||||
'other' => Email::Other,
|
||||
);
|
||||
|
||||
public $addresstypes = array(
|
||||
'home' => Address::Home,
|
||||
'work' => Address::Work,
|
||||
|
@ -125,10 +131,21 @@ class kolab_format_contact extends kolab_format
|
|||
}
|
||||
$org->setRelateds($rels);
|
||||
|
||||
// email, im, url
|
||||
$this->obj->setEmailAddresses(self::array2vector($object['email']));
|
||||
// im, email, url
|
||||
$this->obj->setIMaddresses(self::array2vector($object['im']));
|
||||
|
||||
if (class_exists('vectoremail')) {
|
||||
$vemails = new vectoremail;
|
||||
foreach ((array)$object['email'] as $email) {
|
||||
$type = $this->emailtypes[$email['type']];
|
||||
$vemails->push(new Email($email['address'], intval($type)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$vemails = self::array2vector(array_map(function($v){ return $v['address']; }, $object['email']));
|
||||
}
|
||||
$this->obj->setEmailAddresses($vemails);
|
||||
|
||||
$vurls = new vectorurl;
|
||||
foreach ((array)$object['website'] as $url) {
|
||||
$type = $url['type'] == 'blog' ? Url::Blog : Url::NoType;
|
||||
|
@ -290,8 +307,19 @@ class kolab_format_contact extends kolab_format
|
|||
$this->read_relateds($org->relateds(), $object);
|
||||
}
|
||||
|
||||
$object['email'] = self::vector2array($this->obj->emailAddresses());
|
||||
$object['im'] = self::vector2array($this->obj->imAddresses());
|
||||
$object['im'] = self::vector2array($this->obj->imAddresses());
|
||||
|
||||
$emails = $this->obj->emailAddresses();
|
||||
if ($emails instanceof vectoremail) {
|
||||
$emailtypes = array_flip($this->emailtypes);
|
||||
for ($i=0; $i < $emails->size(); $i++) {
|
||||
$email = $emails->get($i);
|
||||
$object['email'][] = array('address' => $email->address(), 'type' => $emailtypes[$email->types()]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$object['email'] = self::vector2array($emails);
|
||||
}
|
||||
|
||||
$urls = $this->obj->urls();
|
||||
for ($i=0; $i < $urls->size(); $i++) {
|
||||
|
|
Loading…
Add table
Reference in a new issue