[Svn] r4244 - in trunk/plugins/kolab_addressbook: . lib

trac at roundcube.net trac at roundcube.net
Sun Nov 21 17:47:51 CET 2010


Author: thomasb
Date: 2010-11-21 10:47:51 -0600 (Sun, 21 Nov 2010)
New Revision: 4244

Modified:
   trunk/plugins/kolab_addressbook/kolab_addressbook.php
   trunk/plugins/kolab_addressbook/lib/rcube_kolab.php
   trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php
Log:
Map more fields of the Kolab contact format (still read-only)

Modified: trunk/plugins/kolab_addressbook/kolab_addressbook.php
===================================================================
--- trunk/plugins/kolab_addressbook/kolab_addressbook.php	2010-11-21 16:47:21 UTC (rev 4243)
+++ trunk/plugins/kolab_addressbook/kolab_addressbook.php	2010-11-21 16:47:51 UTC (rev 4244)
@@ -29,6 +29,7 @@
         
         $this->add_hook('addressbooks_list', array($this, 'address_sources'));
         $this->add_hook('addressbook_get', array($this, 'get_address_book'));
+        $this->add_hook('contact_form', array($this, 'contact_form'));
 
         // extend include path to load bundled Horde classes
         $include_path = $this->home . '/lib' . PATH_SEPARATOR . ini_get('include_path');
@@ -112,5 +113,24 @@
         
         return $this->sources;
     }
+    
+    
+    /**
+     * Plugin hook called before rendering the contact form or detail view
+     */
+    public function contact_form($p)
+    {
+        // extend the list of contact fields to be displayed in the 'info' section
+        if (is_array($p['form']['info'])) {
+            $p['form']['info']['content']['initials'] = array('size' => 6);
+            $p['form']['info']['content']['anniversary'] = array('size' => 12, 'render_func' => 'rcmail_format_date_col');
+            
+            // TODO: add more Kolab-specific fields
+            
+            // TODO: re-order fields
+        }
+        
+        return $p;
+    }
 
 }

Modified: trunk/plugins/kolab_addressbook/lib/rcube_kolab.php
===================================================================
--- trunk/plugins/kolab_addressbook/lib/rcube_kolab.php	2010-11-21 16:47:21 UTC (rev 4243)
+++ trunk/plugins/kolab_addressbook/lib/rcube_kolab.php	2010-11-21 16:47:51 UTC (rev 4244)
@@ -1,6 +1,7 @@
 <?php
 
 require_once 'Horde/Kolab/Storage/List.php';
+require_once 'Horde/Kolab/Format.php';
 require_once 'Horde/Auth.php';
 require_once 'Horde/Auth/kolab.php';
 require_once 'Horde/Perms.php';
@@ -48,6 +49,19 @@
             Auth::setCredential('password', $pwd);
         }
     }
+    
+    
+    /**
+     * Get instance of a Kolab (XML) format object
+     *
+     * @param string Data type (contact,event,task,note)
+     * @return object Horde_Kolab_Format_XML The format object
+     */
+    public static function get_format($type)
+    {
+      self::setup();
+      return Horde_Kolab_Format::factory('XML', $type);
+    }
 
     /**
      * Get a list of storage folders for the given data type

Modified: trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php
===================================================================
--- trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php	2010-11-21 16:47:21 UTC (rev 4243)
+++ trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php	2010-11-21 16:47:51 UTC (rev 4244)
@@ -15,6 +15,30 @@
     public $primary_key = 'ID';
     public $readonly = true;
     public $groups = true;
+    public $coltypes = array(
+      'name'         => array('limit' => 1),
+      'firstname'    => array('limit' => 1),
+      'surname'      => array('limit' => 1),
+      'middlename'   => array('limit' => 1),
+      'prefix'       => array('limit' => 1),
+      'suffix'       => array('limit' => 1),
+      'nickname'     => array('limit' => 1),
+      'jobtitle'     => array('limit' => 1),
+      'organization' => array('limit' => 1),
+      'department'   => array('limit' => 1),
+      'gender'       => array('limit' => 1),
+      'birthday'     => array('limit' => 1),
+      'email'        => array(),
+      'phone'        => array(),
+      'im'           => array('limit' => 1),
+      'website'      => array('limit' => 1),
+      'address'      => array(),
+      'notes'        => array(),
+      // define additional coltypes
+      'initials'     => array('type' => 'text', 'size' => 6, 'limit' => 1),
+      'anniversary'  => array('type' => 'date', 'size' => 12, 'limit' => 1),
+      // TODO: define more Kolab-specific fields such as: office-location, profession, manager-name, assistant, spouse-name, children, language, latitude, longitude, pgp-publickey, free-busy-url
+    );
 
     private $gid;
     private $imap;
@@ -28,12 +52,19 @@
     private $filter;
     private $result;
     private $imap_folder = 'INBOX/Contacts';
+    private $gender_map = array(0 => 'male', 1 => 'female');
 
 
     public function __construct($imap_folder = null)
     {
         if ($imap_folder)
             $this->imap_folder = $imap_folder;
+            
+        // extend coltypes configuration 
+        $format = rcube_kolab::get_format('contact');
+        $this->coltypes['phone']['subtypes'] = $format->_phone_types;
+        $this->coltypes['address']['subtypes'] = $format->_address_types;
+        $this->coltypes['anniversary']['label'] = rcube_label('anniversary');
         
         // fetch objects from the given IMAP folder
         $this->contactstorage = rcube_kolab::get_storage($this->imap_folder);
@@ -293,13 +324,53 @@
      */
     private function _to_rcube_contact($record)
     {
-        return array(
+        $out = array(
           'ID' => md5($record['uid']),
           'name' => $record['full-name'],
           'firstname' => $record['given-name'],
+          'middlename' => $record['middle-names'],
           'surname' => $record['last-name'],
-          'email' => $record['emails'],
+          'prefix' => $record['prefix'],
+          'suffix' => $record['suffix'],
+          'nickname' => $record['nick-name'],
+          'organization' => $record['organization'],
+          'department' => $record['department'],
+          'jobtitle' => $record['job-title'],
+          'initials' => $record['initials'],
+          'birthday' => $record['birthday'],
+          'anniversary' => $record['anniversary'],
+          'email' => array(),
+          'phone' => array(),
+          'notes' => $record['body'],
         );
+        
+        if (isset($record['gender']))
+            $out['gender'] = $this->gender_map[$record['gender']];
+
+        foreach ((array)$record['email'] as $i => $email)
+            $out['email'][] = $email['smtp-address'];
+
+        foreach ((array)$record['phone'] as $i => $phone)
+            $out['phone:'.$phone['type']][] = $phone['number'];
+            
+        if ($record['im-address'])
+            $out['im:aim'] = array($record['im-address']);
+        if ($record['web-page'])
+            $out['website:work'] = array($record['web-page']);
+
+        if ($record['addr-home-type']) {
+            $key = 'address:' . $record['addr-home-type'];
+            $out[$key][] = array(
+                'street' => $record['addr-home-street'],
+                'locality' => $record['addr-home-locality'],
+                'zipcode' => $record['addr-home-postal-code'],
+                'region' => $record['addr-home-region'],
+                'country' => $record['addr-home-country'],
+            );
+        }
+
+        // remove empty fields
+        return array_filter($out);
     }
 
     private function _from_rcube_contact($contact)

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list