summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-05-01 13:19:13 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-05-01 13:19:13 (GMT)
commit2c71f81e7057599266dd0714e79ce9d495b80ca8 (patch)
tree581ad2f9564fc7f93ceb039f8d4d1bb16a2ce1e2
parent398cd6793a4fdd1a4e15ca34229883aedf2b6fb4 (diff)
parent02fc214d007974596d768ee84ee3595195c8a6d9 (diff)
downloadroundcubemail-plugins-kolab-2c71f81e7057599266dd0714e79ce9d495b80ca8.tar.gz
Merge branch 'dev/email-subtypes'
-rw-r--r--plugins/kolab_addressbook/lib/rcube_kolab_contacts.php57
-rw-r--r--plugins/libkolab/lib/kolab_format_contact.php36
2 files changed, 52 insertions, 41 deletions
diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
index 4ff585f..48b89be 100644
--- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
+++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
@@ -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];
+ }
}
}
@@ -1098,31 +1092,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();
- $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);
+ // 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]);
}
- unset($contact['phone:'.$type]);
}
+ $addresses = array();
foreach ($this->get_col_values('address', $contact) as $type => $values) {
foreach ((array)$values as $adr) {
// skip empty address
@@ -1143,8 +1128,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
diff --git a/plugins/libkolab/lib/kolab_format_contact.php b/plugins/libkolab/lib/kolab_format_contact.php
index 3676f05..19ee0b8 100644
--- a/plugins/libkolab/lib/kolab_format_contact.php
+++ b/plugins/libkolab/lib/kolab_format_contact.php
@@ -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++) {