plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Wed Nov 6 13:39:11 CET 2013


 plugins/libkolab/lib/kolab_format_contact.php |   39 +++++++++++++-------------
 1 file changed, 20 insertions(+), 19 deletions(-)

New commits:
commit b5d7d3d76511d5966288c8c518aa9bd6a06e6b30
Author: Thomas Bruederli <thomas at roundcube.net>
Date:   Wed Nov 6 13:38:57 2013 +0100

    Fix wrong mapping of title/role fields in contacts + simplified saving of relateds

diff --git a/plugins/libkolab/lib/kolab_format_contact.php b/plugins/libkolab/lib/kolab_format_contact.php
index 0d0bc75..b9b6de6 100644
--- a/plugins/libkolab/lib/kolab_format_contact.php
+++ b/plugins/libkolab/lib/kolab_format_contact.php
@@ -107,8 +107,8 @@ class kolab_format_contact extends kolab_format
 
         if (isset($object['nickname']))
             $this->obj->setNickNames(self::array2vector($object['nickname']));
-        if (isset($object['profession']))
-            $this->obj->setTitles(self::array2vector($object['profession']));
+        if (isset($object['jobtitle']))
+            $this->obj->setTitles(self::array2vector($object['jobtitle']));
 
         // organisation related properties (affiliation)
         $org = new Affiliation;
@@ -117,17 +117,17 @@ class kolab_format_contact extends kolab_format
             $org->setOrganisation($object['organization']);
         if ($object['department'])
             $org->setOrganisationalUnits(self::array2vector($object['department']));
-        if ($object['jobtitle'])
-            $org->setRoles(self::array2vector($object['jobtitle']));
+        if ($object['profession'])
+            $org->setRoles(self::array2vector($object['profession']));
 
         $rels = new vectorrelated;
-        if ($object['manager']) {
-            foreach ((array)$object['manager'] as $manager)
-                $rels->push(new Related(Related::Text, $manager, Related::Manager));
-        }
-        if ($object['assistant']) {
-            foreach ((array)$object['assistant'] as $assistant)
-                $rels->push(new Related(Related::Text, $assistant, Related::Assistant));
+        foreach (array('manager','assistant') as $field) {
+            if (!empty($object[$field])) {
+                $reltype = $this->relatedmap[$field];
+                foreach ((array)$object[$field] as $value) {
+                    $rels->push(new Related(Related::Text, $value, $reltype));
+                }
+            }
         }
         $org->setRelateds($rels);
 
@@ -219,12 +219,13 @@ class kolab_format_contact extends kolab_format
 
         // spouse and children are relateds
         $rels = new vectorrelated;
-        if ($object['spouse']) {
-            $rels->push(new Related(Related::Text, $object['spouse'], Related::Spouse));
-        }
-        if ($object['children']) {
-            foreach ((array)$object['children'] as $child)
-                $rels->push(new Related(Related::Text, $child, Related::Child));
+        foreach (array('spouse','children') as $field) {
+            if (!empty($object[$field])) {
+                $reltype = $this->relatedmap[$field];
+                foreach ((array)$object[$field] as $value) {
+                    $rels->push(new Related(Related::Text, $value, $reltype));
+                }
+            }
         }
         $this->obj->setRelateds($rels);
 
@@ -296,7 +297,7 @@ class kolab_format_contact extends kolab_format
         $object['prefix']     = join(' ', self::vector2array($nc->prefixes()));
         $object['suffix']     = join(' ', self::vector2array($nc->suffixes()));
         $object['nickname']   = join(' ', self::vector2array($this->obj->nickNames()));
-        $object['profession'] = join(' ', self::vector2array($this->obj->titles()));
+        $object['jobtitle']   = join(' ', self::vector2array($this->obj->titles()));
         $object['categories'] = self::vector2array($this->obj->categories());
 
         // organisation related properties (affiliation)
@@ -304,7 +305,7 @@ class kolab_format_contact extends kolab_format
         if ($orgs->size()) {
             $org = $orgs->get(0);
             $object['organization']   = $org->organisation();
-            $object['jobtitle']       = join(' ', self::vector2array($org->roles()));
+            $object['profession']     = join(' ', self::vector2array($org->roles()));
             $object['department']     = join(' ', self::vector2array($org->organisationalUnits()));
             $this->read_relateds($org->relateds(), $object);
         }




More information about the commits mailing list