3 commits - plugins/kolab_addressbook plugins/libkolab
Thomas Brüderli
bruederli at kolabsys.com
Wed May 1 15:26:14 CEST 2013
plugins/kolab_addressbook/lib/rcube_kolab_contacts.php | 57 +++++------------
plugins/libkolab/lib/kolab_format_contact.php | 36 +++++++++-
2 files changed, 52 insertions(+), 41 deletions(-)
New commits:
commit 72e4984952d06e2debffd148463ac5f1408d8738
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed May 1 15:25:37 2013 +0200
Use the correct email type constant
diff --git a/plugins/libkolab/lib/kolab_format_contact.php b/plugins/libkolab/lib/kolab_format_contact.php
index 19ee0b8..99b25bc 100644
--- a/plugins/libkolab/lib/kolab_format_contact.php
+++ b/plugins/libkolab/lib/kolab_format_contact.php
@@ -50,7 +50,7 @@ class kolab_format_contact extends kolab_format
public $emailtypes = array(
'home' => Email::Home,
'work' => Email::Work,
- 'other' => Email::Other,
+ 'other' => Email::NoType,
);
public $addresstypes = array(
commit 2c71f81e7057599266dd0714e79ce9d495b80ca8
Merge: 398cd67 02fc214
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed May 1 15:19:13 2013 +0200
Merge branch 'dev/email-subtypes'
commit 02fc214d007974596d768ee84ee3595195c8a6d9
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Thu Mar 21 10:02:35 2013 +0100
Adapt libkolab and kolab_addressbook to support type parameters for email addresses
diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
index 6e32bc7..9e3ea91 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];
+ }
}
}
@@ -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();
- $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
@@ -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
diff --git a/plugins/libkolab/lib/kolab_format_contact.php b/plugins/libkolab/lib/kolab_format_contact.php
index cde0288..22075ca 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++) {
More information about the commits
mailing list