Changeset 4244 in subversion


Ignore:
Timestamp:
Nov 21, 2010 11:47:51 AM (3 years ago)
Author:
thomasb
Message:

Map more fields of the Kolab contact format (still read-only)

Location:
trunk/plugins/kolab_addressbook
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/kolab_addressbook/kolab_addressbook.php

    r4205 r4244  
    3030        $this->add_hook('addressbooks_list', array($this, 'address_sources')); 
    3131        $this->add_hook('addressbook_get', array($this, 'get_address_book')); 
     32        $this->add_hook('contact_form', array($this, 'contact_form')); 
    3233 
    3334        // extend include path to load bundled Horde classes 
     
    113114        return $this->sources; 
    114115    } 
     116     
     117     
     118    /** 
     119     * Plugin hook called before rendering the contact form or detail view 
     120     */ 
     121    public function contact_form($p) 
     122    { 
     123        // extend the list of contact fields to be displayed in the 'info' section 
     124        if (is_array($p['form']['info'])) { 
     125            $p['form']['info']['content']['initials'] = array('size' => 6); 
     126            $p['form']['info']['content']['anniversary'] = array('size' => 12, 'render_func' => 'rcmail_format_date_col'); 
     127             
     128            // TODO: add more Kolab-specific fields 
     129             
     130            // TODO: re-order fields 
     131        } 
     132         
     133        return $p; 
     134    } 
    115135 
    116136} 
  • trunk/plugins/kolab_addressbook/lib/rcube_kolab.php

    r4205 r4244  
    22 
    33require_once 'Horde/Kolab/Storage/List.php'; 
     4require_once 'Horde/Kolab/Format.php'; 
    45require_once 'Horde/Auth.php'; 
    56require_once 'Horde/Auth/kolab.php'; 
     
    4950        } 
    5051    } 
     52     
     53     
     54    /** 
     55     * Get instance of a Kolab (XML) format object 
     56     * 
     57     * @param string Data type (contact,event,task,note) 
     58     * @return object Horde_Kolab_Format_XML The format object 
     59     */ 
     60    public static function get_format($type) 
     61    { 
     62      self::setup(); 
     63      return Horde_Kolab_Format::factory('XML', $type); 
     64    } 
    5165 
    5266    /** 
  • trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php

    r4206 r4244  
    1616    public $readonly = true; 
    1717    public $groups = true; 
     18    public $coltypes = array( 
     19      'name'         => array('limit' => 1), 
     20      'firstname'    => array('limit' => 1), 
     21      'surname'      => array('limit' => 1), 
     22      'middlename'   => array('limit' => 1), 
     23      'prefix'       => array('limit' => 1), 
     24      'suffix'       => array('limit' => 1), 
     25      'nickname'     => array('limit' => 1), 
     26      'jobtitle'     => array('limit' => 1), 
     27      'organization' => array('limit' => 1), 
     28      'department'   => array('limit' => 1), 
     29      'gender'       => array('limit' => 1), 
     30      'birthday'     => array('limit' => 1), 
     31      'email'        => array(), 
     32      'phone'        => array(), 
     33      'im'           => array('limit' => 1), 
     34      'website'      => array('limit' => 1), 
     35      'address'      => array(), 
     36      'notes'        => array(), 
     37      // define additional coltypes 
     38      'initials'     => array('type' => 'text', 'size' => 6, 'limit' => 1), 
     39      'anniversary'  => array('type' => 'date', 'size' => 12, 'limit' => 1), 
     40      // 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 
     41    ); 
    1842 
    1943    private $gid; 
     
    2953    private $result; 
    3054    private $imap_folder = 'INBOX/Contacts'; 
     55    private $gender_map = array(0 => 'male', 1 => 'female'); 
    3156 
    3257 
     
    3560        if ($imap_folder) 
    3661            $this->imap_folder = $imap_folder; 
     62             
     63        // extend coltypes configuration  
     64        $format = rcube_kolab::get_format('contact'); 
     65        $this->coltypes['phone']['subtypes'] = $format->_phone_types; 
     66        $this->coltypes['address']['subtypes'] = $format->_address_types; 
     67        $this->coltypes['anniversary']['label'] = rcube_label('anniversary'); 
    3768         
    3869        // fetch objects from the given IMAP folder 
     
    294325    private function _to_rcube_contact($record) 
    295326    { 
    296         return array( 
     327        $out = array( 
    297328          'ID' => md5($record['uid']), 
    298329          'name' => $record['full-name'], 
    299330          'firstname' => $record['given-name'], 
     331          'middlename' => $record['middle-names'], 
    300332          'surname' => $record['last-name'], 
    301           'email' => $record['emails'], 
     333          'prefix' => $record['prefix'], 
     334          'suffix' => $record['suffix'], 
     335          'nickname' => $record['nick-name'], 
     336          'organization' => $record['organization'], 
     337          'department' => $record['department'], 
     338          'jobtitle' => $record['job-title'], 
     339          'initials' => $record['initials'], 
     340          'birthday' => $record['birthday'], 
     341          'anniversary' => $record['anniversary'], 
     342          'email' => array(), 
     343          'phone' => array(), 
     344          'notes' => $record['body'], 
    302345        ); 
     346         
     347        if (isset($record['gender'])) 
     348            $out['gender'] = $this->gender_map[$record['gender']]; 
     349 
     350        foreach ((array)$record['email'] as $i => $email) 
     351            $out['email'][] = $email['smtp-address']; 
     352 
     353        foreach ((array)$record['phone'] as $i => $phone) 
     354            $out['phone:'.$phone['type']][] = $phone['number']; 
     355             
     356        if ($record['im-address']) 
     357            $out['im:aim'] = array($record['im-address']); 
     358        if ($record['web-page']) 
     359            $out['website:work'] = array($record['web-page']); 
     360 
     361        if ($record['addr-home-type']) { 
     362            $key = 'address:' . $record['addr-home-type']; 
     363            $out[$key][] = array( 
     364                'street' => $record['addr-home-street'], 
     365                'locality' => $record['addr-home-locality'], 
     366                'zipcode' => $record['addr-home-postal-code'], 
     367                'region' => $record['addr-home-region'], 
     368                'country' => $record['addr-home-country'], 
     369            ); 
     370        } 
     371 
     372        // remove empty fields 
     373        return array_filter($out); 
    303374    } 
    304375 
Note: See TracChangeset for help on using the changeset viewer.