2012-03-06 09:58:01 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-14 19:48:54 +01:00
|
|
|
/**
|
|
|
|
* Kolab Contact model class
|
|
|
|
*
|
|
|
|
* @version @package_version@
|
|
|
|
* @author Thomas Bruederli <bruederli@kolabsys.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012, Kolab Systems AG <contact@kolabsys.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2012-03-06 09:58:01 +01:00
|
|
|
|
|
|
|
class kolab_format_contact extends kolab_format
|
|
|
|
{
|
|
|
|
public $CTYPE = 'application/vcard+xml';
|
2012-03-06 22:23:34 +01:00
|
|
|
|
2012-05-22 10:14:56 +02:00
|
|
|
protected $read_func = 'kolabformat::readContact';
|
|
|
|
protected $write_func = 'kolabformat::writeContact';
|
|
|
|
|
2012-05-15 19:05:46 +02:00
|
|
|
public static $fulltext_cols = array('name', 'firstname', 'surname', 'middlename', 'email');
|
|
|
|
|
2012-03-06 22:23:34 +01:00
|
|
|
public $phonetypes = array(
|
|
|
|
'home' => Telephone::Home,
|
|
|
|
'work' => Telephone::Work,
|
|
|
|
'text' => Telephone::Text,
|
|
|
|
'main' => Telephone::Voice,
|
|
|
|
'homefax' => Telephone::Fax,
|
|
|
|
'workfax' => Telephone::Fax,
|
|
|
|
'mobile' => Telephone::Cell,
|
|
|
|
'video' => Telephone::Video,
|
|
|
|
'pager' => Telephone::Pager,
|
|
|
|
'car' => Telephone::Car,
|
|
|
|
'other' => Telephone::Textphone,
|
|
|
|
);
|
|
|
|
|
|
|
|
public $addresstypes = array(
|
|
|
|
'home' => Address::Home,
|
|
|
|
'work' => Address::Work,
|
2012-03-21 15:33:30 +01:00
|
|
|
'office' => 0,
|
2012-03-06 22:23:34 +01:00
|
|
|
);
|
|
|
|
|
2012-03-14 18:51:38 +01:00
|
|
|
private $gendermap = array(
|
|
|
|
'female' => Contact::Female,
|
2012-03-20 23:51:43 +01:00
|
|
|
'male' => Contact::Male,
|
|
|
|
);
|
|
|
|
|
|
|
|
private $relatedmap = array(
|
|
|
|
'manager' => Related::Manager,
|
|
|
|
'assistant' => Related::Assistant,
|
|
|
|
'spouse' => Related::Spouse,
|
|
|
|
'children' => Related::Child,
|
2012-03-14 18:51:38 +01:00
|
|
|
);
|
2012-03-06 09:58:01 +01:00
|
|
|
|
|
|
|
// old Kolab 2 format field map
|
|
|
|
private $kolab2_fieldmap = array(
|
|
|
|
// kolab => roundcube
|
|
|
|
'full-name' => 'name',
|
|
|
|
'given-name' => 'firstname',
|
|
|
|
'middle-names' => 'middlename',
|
|
|
|
'last-name' => 'surname',
|
|
|
|
'prefix' => 'prefix',
|
|
|
|
'suffix' => 'suffix',
|
|
|
|
'nick-name' => 'nickname',
|
|
|
|
'organization' => 'organization',
|
|
|
|
'department' => 'department',
|
|
|
|
'job-title' => 'jobtitle',
|
|
|
|
'birthday' => 'birthday',
|
|
|
|
'anniversary' => 'anniversary',
|
|
|
|
'phone' => 'phone',
|
|
|
|
'im-address' => 'im',
|
|
|
|
'web-page' => 'website',
|
|
|
|
'profession' => 'profession',
|
|
|
|
'manager-name' => 'manager',
|
|
|
|
'assistant' => 'assistant',
|
|
|
|
'spouse-name' => 'spouse',
|
|
|
|
'children' => 'children',
|
|
|
|
'body' => 'notes',
|
|
|
|
'pgp-publickey' => 'pgppublickey',
|
|
|
|
'free-busy-url' => 'freebusyurl',
|
2012-03-08 10:21:21 +01:00
|
|
|
'picture' => 'photo',
|
2012-03-06 09:58:01 +01:00
|
|
|
);
|
2012-03-06 22:23:34 +01:00
|
|
|
private $kolab2_phonetypes = array(
|
|
|
|
'home1' => 'home',
|
|
|
|
'business1' => 'work',
|
|
|
|
'business2' => 'work',
|
|
|
|
'businessfax' => 'workfax',
|
|
|
|
);
|
|
|
|
private $kolab2_addresstypes = array(
|
|
|
|
'business' => 'work'
|
|
|
|
);
|
|
|
|
private $kolab2_gender = array(0 => 'male', 1 => 'female');
|
2012-03-06 09:58:01 +01:00
|
|
|
|
2012-03-06 22:23:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
2012-05-02 17:41:02 +02:00
|
|
|
function __construct($xmldata = null)
|
2012-03-06 09:58:01 +01:00
|
|
|
{
|
|
|
|
$this->obj = new Contact;
|
2012-05-02 17:41:02 +02:00
|
|
|
$this->xmldata = $xmldata;
|
2012-03-06 22:23:34 +01:00
|
|
|
|
|
|
|
// complete phone types
|
|
|
|
$this->phonetypes['homefax'] |= Telephone::Home;
|
|
|
|
$this->phonetypes['workfax'] |= Telephone::Work;
|
2012-03-06 09:58:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set contact properties to the kolabformat object
|
|
|
|
*
|
|
|
|
* @param array Contact data as hash array
|
|
|
|
*/
|
|
|
|
public function set(&$object)
|
|
|
|
{
|
2012-05-02 17:41:02 +02:00
|
|
|
$this->init();
|
|
|
|
|
2012-03-06 09:58:01 +01:00
|
|
|
// set some automatic values if missing
|
|
|
|
if (false && !$this->obj->created()) {
|
|
|
|
if (!empty($object['created']))
|
|
|
|
$object['created'] = new DateTime('now', self::$timezone);
|
2012-03-08 10:21:21 +01:00
|
|
|
$this->obj->setCreated(self::get_datetime($object['created']));
|
2012-03-06 09:58:01 +01:00
|
|
|
}
|
|
|
|
|
2012-03-14 18:51:38 +01:00
|
|
|
if (!empty($object['uid']))
|
|
|
|
$this->obj->setUid($object['uid']);
|
2012-03-06 09:58:01 +01:00
|
|
|
|
2012-06-26 16:31:42 +02:00
|
|
|
$object['changed'] = new DateTime('now', self::$timezone);
|
|
|
|
|
2012-03-14 18:51:38 +01:00
|
|
|
// do the hard work of setting object values
|
2012-03-06 09:58:01 +01:00
|
|
|
$nc = new NameComponents;
|
2012-03-06 22:23:34 +01:00
|
|
|
$nc->setSurnames(self::array2vector($object['surname']));
|
|
|
|
$nc->setGiven(self::array2vector($object['firstname']));
|
|
|
|
$nc->setAdditional(self::array2vector($object['middlename']));
|
|
|
|
$nc->setPrefixes(self::array2vector($object['prefix']));
|
|
|
|
$nc->setSuffixes(self::array2vector($object['suffix']));
|
2012-03-06 09:58:01 +01:00
|
|
|
$this->obj->setNameComponents($nc);
|
|
|
|
$this->obj->setName($object['name']);
|
|
|
|
|
2012-03-14 18:51:38 +01:00
|
|
|
if (isset($object['nickname']))
|
2012-03-06 22:23:34 +01:00
|
|
|
$this->obj->setNickNames(self::array2vector($object['nickname']));
|
2012-03-21 15:33:30 +01:00
|
|
|
if (isset($object['profession']))
|
|
|
|
$this->obj->setTitles(self::array2vector($object['profession']));
|
2012-03-06 22:23:34 +01:00
|
|
|
|
|
|
|
// organisation related properties (affiliation)
|
|
|
|
$org = new Affiliation;
|
2012-03-21 15:33:30 +01:00
|
|
|
$offices = new vectoraddress;
|
2012-03-06 22:23:34 +01:00
|
|
|
if ($object['organization'])
|
|
|
|
$org->setOrganisation($object['organization']);
|
2012-03-20 23:51:43 +01:00
|
|
|
if ($object['department'])
|
|
|
|
$org->setOrganisationalUnits(self::array2vector($object['department']));
|
2012-03-06 22:23:34 +01:00
|
|
|
if ($object['jobtitle'])
|
2012-03-20 23:51:43 +01:00
|
|
|
$org->setRoles(self::array2vector($object['jobtitle']));
|
|
|
|
|
|
|
|
$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));
|
|
|
|
}
|
|
|
|
$org->setRelateds($rels);
|
2012-03-06 22:23:34 +01:00
|
|
|
|
|
|
|
// email, im, url
|
|
|
|
$this->obj->setEmailAddresses(self::array2vector($object['email']));
|
|
|
|
$this->obj->setIMaddresses(self::array2vector($object['im']));
|
2012-04-21 18:23:11 +02:00
|
|
|
|
|
|
|
$vurls = new vectorurl;
|
|
|
|
foreach ((array)$object['website'] as $url) {
|
2012-06-12 11:30:13 +02:00
|
|
|
$type = $url['type'] == 'blog' ? Url::Blog : Url::NoType;
|
2012-04-21 18:23:11 +02:00
|
|
|
$vurls->push(new Url($url['url'], $type));
|
|
|
|
}
|
|
|
|
$this->obj->setUrls($vurls);
|
2012-03-06 09:58:01 +01:00
|
|
|
|
|
|
|
// addresses
|
|
|
|
$adrs = new vectoraddress;
|
2012-05-15 19:05:46 +02:00
|
|
|
foreach ((array)$object['address'] as $address) {
|
2012-03-06 09:58:01 +01:00
|
|
|
$adr = new Address;
|
2012-03-06 22:23:34 +01:00
|
|
|
$type = $this->addresstypes[$address['type']];
|
|
|
|
if (isset($type))
|
|
|
|
$adr->setTypes($type);
|
|
|
|
else if ($address['type'])
|
|
|
|
$adr->setLabel($address['type']);
|
2012-03-06 09:58:01 +01:00
|
|
|
if ($address['street'])
|
|
|
|
$adr->setStreet($address['street']);
|
|
|
|
if ($address['locality'])
|
|
|
|
$adr->setLocality($address['locality']);
|
|
|
|
if ($address['code'])
|
|
|
|
$adr->setCode($address['code']);
|
|
|
|
if ($address['region'])
|
|
|
|
$adr->setRegion($address['region']);
|
|
|
|
if ($address['country'])
|
|
|
|
$adr->setCountry($address['country']);
|
|
|
|
|
2012-03-21 15:33:30 +01:00
|
|
|
if ($address['type'] == 'office')
|
|
|
|
$offices->push($adr);
|
|
|
|
else
|
|
|
|
$adrs->push($adr);
|
2012-03-06 09:58:01 +01:00
|
|
|
}
|
|
|
|
$this->obj->setAddresses($adrs);
|
2012-03-21 15:33:30 +01:00
|
|
|
$org->setAddresses($offices);
|
|
|
|
|
|
|
|
// add org affiliation after addresses are set
|
|
|
|
$orgs = new vectoraffiliation;
|
|
|
|
$orgs->push($org);
|
|
|
|
$this->obj->setAffiliations($orgs);
|
2012-03-06 09:58:01 +01:00
|
|
|
|
2012-03-06 22:23:34 +01:00
|
|
|
// telephones
|
|
|
|
$tels = new vectortelephone;
|
|
|
|
foreach ((array)$object['phone'] as $phone) {
|
|
|
|
$tel = new Telephone;
|
|
|
|
if (isset($this->phonetypes[$phone['type']]))
|
|
|
|
$tel->setTypes($this->phonetypes[$phone['type']]);
|
|
|
|
$tel->setNumber($phone['number']);
|
|
|
|
$tels->push($tel);
|
|
|
|
}
|
|
|
|
$this->obj->setTelephones($tels);
|
|
|
|
|
2012-03-14 18:51:38 +01:00
|
|
|
if (isset($object['gender']))
|
|
|
|
$this->obj->setGender($this->gendermap[$object['gender']] ? $this->gendermap[$object['gender']] : Contact::NotSet);
|
|
|
|
if (isset($object['notes']))
|
2012-03-06 22:23:34 +01:00
|
|
|
$this->obj->setNote($object['notes']);
|
2012-03-14 18:51:38 +01:00
|
|
|
if (isset($object['freebusyurl']))
|
2012-03-06 22:23:34 +01:00
|
|
|
$this->obj->setFreeBusyUrl($object['freebusyurl']);
|
2012-03-14 18:51:38 +01:00
|
|
|
if (isset($object['birthday']))
|
2012-05-23 15:39:53 +02:00
|
|
|
$this->obj->setBDay(self::get_datetime($object['birthday'], false, true));
|
2012-03-14 18:51:38 +01:00
|
|
|
if (isset($object['anniversary']))
|
2012-05-23 15:39:53 +02:00
|
|
|
$this->obj->setAnniversary(self::get_datetime($object['anniversary'], false, true));
|
2012-03-06 22:23:34 +01:00
|
|
|
|
2012-03-14 11:22:42 +01:00
|
|
|
if (!empty($object['photo'])) {
|
2012-03-20 23:51:43 +01:00
|
|
|
if ($type = rc_image_content_type($object['photo']))
|
2012-03-14 11:22:42 +01:00
|
|
|
$this->obj->setPhoto($object['photo'], $type);
|
|
|
|
}
|
2012-05-02 17:41:02 +02:00
|
|
|
else if (isset($object['photo']))
|
2012-03-14 11:22:42 +01:00
|
|
|
$this->obj->setPhoto('','');
|
2012-05-02 17:41:02 +02:00
|
|
|
else if ($this->obj->photoMimetype()) // load saved photo for caching
|
|
|
|
$object['photo'] = $this->obj->photo();
|
2012-03-14 11:22:42 +01:00
|
|
|
|
2012-03-20 23:51:43 +01:00
|
|
|
// 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));
|
|
|
|
}
|
|
|
|
$this->obj->setRelateds($rels);
|
|
|
|
|
2012-04-25 14:12:09 +02:00
|
|
|
// insert/replace crypto keys
|
|
|
|
$pgp_index = $pkcs7_index = -1;
|
|
|
|
$keys = $this->obj->keys();
|
|
|
|
for ($i=0; $i < $keys->size(); $i++) {
|
|
|
|
$key = $keys->get($i);
|
|
|
|
if ($pgp_index < 0 && $key->type() == Key::PGP)
|
|
|
|
$pgp_index = $i;
|
|
|
|
else if ($pkcs7_index < 0 && $key->type() == Key::PKCS7_MIME)
|
|
|
|
$pkcs7_index = $i;
|
2012-03-21 16:15:53 +01:00
|
|
|
}
|
|
|
|
|
2012-04-25 14:12:09 +02:00
|
|
|
$pgpkey = $object['pgppublickey'] ? new Key($object['pgppublickey'], Key::PGP) : new Key();
|
|
|
|
$pkcs7key = $object['pkcs7publickey'] ? new Key($object['pkcs7publickey'], Key::PKCS7_MIME) : new Key();
|
|
|
|
|
|
|
|
if ($pgp_index >= 0)
|
|
|
|
$keys->set($pgp_index, $pgpkey);
|
|
|
|
else if (!empty($object['pgppublickey']))
|
|
|
|
$keys->push($pgpkey);
|
|
|
|
if ($pkcs7_index >= 0)
|
|
|
|
$keys->set($pkcs7_index, $pkcs7key);
|
|
|
|
else if (!empty($object['pkcs7publickey']))
|
|
|
|
$keys->push($pkcs7key);
|
|
|
|
|
|
|
|
$this->obj->setKeys($keys);
|
|
|
|
|
2012-03-21 16:15:53 +01:00
|
|
|
// TODO: handle language, gpslocation, etc.
|
2012-03-20 23:51:43 +01:00
|
|
|
|
2012-03-06 22:23:34 +01:00
|
|
|
|
2012-03-06 09:58:01 +01:00
|
|
|
// cache this data
|
|
|
|
$this->data = $object;
|
2012-05-02 17:41:02 +02:00
|
|
|
unset($this->data['_formatobj']);
|
2012-03-06 09:58:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function is_valid()
|
|
|
|
{
|
2012-05-02 17:41:02 +02:00
|
|
|
return $this->data || (is_object($this->obj) && $this->obj->uid() /*$this->obj->isValid()*/);
|
2012-03-06 09:58:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the Contact object into a hash array data structure
|
|
|
|
*
|
|
|
|
* @return array Contact data as hash array
|
|
|
|
*/
|
|
|
|
public function to_array()
|
|
|
|
{
|
|
|
|
// return cached result
|
|
|
|
if (!empty($this->data))
|
|
|
|
return $this->data;
|
|
|
|
|
2012-05-02 17:41:02 +02:00
|
|
|
$this->init();
|
|
|
|
|
2012-03-06 22:23:34 +01:00
|
|
|
// read object properties into local data object
|
2012-03-06 09:58:01 +01:00
|
|
|
$object = array(
|
|
|
|
'uid' => $this->obj->uid(),
|
|
|
|
'name' => $this->obj->name(),
|
2012-05-30 08:51:55 +02:00
|
|
|
'changed' => self::php_datetime($this->obj->lastModified()),
|
2012-03-06 09:58:01 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$nc = $this->obj->nameComponents();
|
|
|
|
$object['surname'] = join(' ', self::vector2array($nc->surnames()));
|
|
|
|
$object['firstname'] = join(' ', self::vector2array($nc->given()));
|
|
|
|
$object['middlename'] = join(' ', self::vector2array($nc->additional()));
|
|
|
|
$object['prefix'] = join(' ', self::vector2array($nc->prefixes()));
|
|
|
|
$object['suffix'] = join(' ', self::vector2array($nc->suffixes()));
|
2012-03-06 22:23:34 +01:00
|
|
|
$object['nickname'] = join(' ', self::vector2array($this->obj->nickNames()));
|
2012-03-21 15:33:30 +01:00
|
|
|
$object['profession'] = join(' ', self::vector2array($this->obj->titles()));
|
2012-03-06 09:58:01 +01:00
|
|
|
|
2012-03-06 22:23:34 +01:00
|
|
|
// organisation related properties (affiliation)
|
|
|
|
$orgs = $this->obj->affiliations();
|
|
|
|
if ($orgs->size()) {
|
|
|
|
$org = $orgs->get(0);
|
|
|
|
$object['organization'] = $org->organisation();
|
2012-03-20 23:51:43 +01:00
|
|
|
$object['jobtitle'] = join(' ', self::vector2array($org->roles()));
|
|
|
|
$object['department'] = join(' ', self::vector2array($org->organisationalUnits()));
|
|
|
|
$this->read_relateds($org->relateds(), $object);
|
2012-03-06 22:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$object['email'] = self::vector2array($this->obj->emailAddresses());
|
|
|
|
$object['im'] = self::vector2array($this->obj->imAddresses());
|
2012-04-21 18:23:11 +02:00
|
|
|
|
|
|
|
$urls = $this->obj->urls();
|
|
|
|
for ($i=0; $i < $urls->size(); $i++) {
|
|
|
|
$url = $urls->get($i);
|
|
|
|
$subtype = $url->type() == Url::Blog ? 'blog' : 'homepage';
|
|
|
|
$object['website'][] = array('url' => $url->url(), 'type' => $subtype);
|
|
|
|
}
|
2012-03-06 09:58:01 +01:00
|
|
|
|
2012-03-06 22:23:34 +01:00
|
|
|
// addresses
|
2012-03-21 15:33:30 +01:00
|
|
|
$this->read_addresses($this->obj->addresses(), $object);
|
|
|
|
if ($org && ($offices = $org->addresses()))
|
|
|
|
$this->read_addresses($offices, $object, 'office');
|
2012-03-06 09:58:01 +01:00
|
|
|
|
2012-03-06 22:23:34 +01:00
|
|
|
// telehones
|
|
|
|
$tels = $this->obj->telephones();
|
|
|
|
$teltypes = array_flip($this->phonetypes);
|
|
|
|
for ($i=0; $i < $tels->size(); $i++) {
|
|
|
|
$tel = $tels->get($i);
|
|
|
|
$object['phone'][] = array('number' => $tel->number(), 'type' => $teltypes[$tel->types()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$object['notes'] = $this->obj->note();
|
|
|
|
$object['freebusyurl'] = $this->obj->freeBusyUrl();
|
2012-03-08 10:21:21 +01:00
|
|
|
|
|
|
|
if ($bday = self::php_datetime($this->obj->bDay()))
|
|
|
|
$object['birthday'] = $bday->format('c');
|
|
|
|
|
|
|
|
if ($anniversary = self::php_datetime($this->obj->anniversary()))
|
|
|
|
$object['anniversary'] = $anniversary->format('c');
|
|
|
|
|
2012-03-14 18:51:38 +01:00
|
|
|
$gendermap = array_flip($this->gendermap);
|
|
|
|
if (($g = $this->obj->gender()) && $gendermap[$g])
|
|
|
|
$object['gender'] = $gendermap[$g];
|
2012-03-06 22:23:34 +01:00
|
|
|
|
2012-03-14 11:22:42 +01:00
|
|
|
if ($this->obj->photoMimetype())
|
|
|
|
$object['photo'] = $this->obj->photo();
|
|
|
|
|
2012-03-20 23:51:43 +01:00
|
|
|
// relateds -> spouse, children
|
|
|
|
$this->read_relateds($this->obj->relateds(), $object);
|
|
|
|
|
2012-04-25 14:12:09 +02:00
|
|
|
// crypto settings: currently only key values are supported
|
2012-04-21 18:23:11 +02:00
|
|
|
$keys = $this->obj->keys();
|
|
|
|
for ($i=0; is_object($keys) && $i < $keys->size(); $i++) {
|
|
|
|
$key = $keys->get($i);
|
2012-04-25 14:12:09 +02:00
|
|
|
if ($key->type() == Key::PGP)
|
2012-04-21 18:23:11 +02:00
|
|
|
$object['pgppublickey'] = $key->key();
|
2012-04-25 14:12:09 +02:00
|
|
|
else if ($key->type() == Key::PKCS7_MIME)
|
|
|
|
$object['pkcs7publickey'] = $key->key();
|
2012-04-21 18:23:11 +02:00
|
|
|
}
|
2012-03-21 16:15:53 +01:00
|
|
|
|
2012-03-06 09:58:01 +01:00
|
|
|
$this->data = $object;
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
2012-05-15 19:05:46 +02:00
|
|
|
/**
|
|
|
|
* Callback for kolab_storage_cache to get words to index for fulltext search
|
|
|
|
*
|
|
|
|
* @return array List of words to save in cache
|
|
|
|
*/
|
|
|
|
public function get_words()
|
|
|
|
{
|
|
|
|
$data = '';
|
|
|
|
foreach (self::$fulltext_cols as $col) {
|
2012-05-16 10:10:51 +02:00
|
|
|
$val = is_array($this->data[$col]) ? join(' ', $this->data[$col]) : $this->data[$col];
|
2012-05-15 19:05:46 +02:00
|
|
|
if (strlen($val))
|
|
|
|
$data .= $val . ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_unique(rcube_utils::normalize_string($data, true));
|
|
|
|
}
|
|
|
|
|
2012-03-06 09:58:01 +01:00
|
|
|
/**
|
|
|
|
* Load data from old Kolab2 format
|
2012-03-14 11:22:42 +01:00
|
|
|
*
|
|
|
|
* @param array Hash array with object properties
|
2012-03-06 09:58:01 +01:00
|
|
|
*/
|
|
|
|
public function fromkolab2($record)
|
|
|
|
{
|
|
|
|
$object = array(
|
|
|
|
'uid' => $record['uid'],
|
|
|
|
'email' => array(),
|
|
|
|
'phone' => array(),
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($this->kolab2_fieldmap as $kolab => $rcube) {
|
|
|
|
if (is_array($record[$kolab]) || strlen($record[$kolab]))
|
|
|
|
$object[$rcube] = $record[$kolab];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($record['gender']))
|
2012-03-06 22:23:34 +01:00
|
|
|
$object['gender'] = $this->kolab2_gender[$record['gender']];
|
2012-03-06 09:58:01 +01:00
|
|
|
|
|
|
|
foreach ((array)$record['email'] as $i => $email)
|
|
|
|
$object['email'][] = $email['smtp-address'];
|
|
|
|
|
|
|
|
if (!$record['email'] && $record['emails'])
|
|
|
|
$object['email'] = preg_split('/,\s*/', $record['emails']);
|
|
|
|
|
|
|
|
if (is_array($record['address'])) {
|
|
|
|
foreach ($record['address'] as $i => $adr) {
|
|
|
|
$object['address'][] = array(
|
2012-03-06 22:23:34 +01:00
|
|
|
'type' => $this->kolab2_addresstypes[$adr['type']] ? $this->kolab2_addresstypes[$adr['type']] : $adr['type'],
|
2012-03-06 09:58:01 +01:00
|
|
|
'street' => $adr['street'],
|
|
|
|
'locality' => $adr['locality'],
|
|
|
|
'code' => $adr['postal-code'],
|
|
|
|
'region' => $adr['region'],
|
|
|
|
'country' => $adr['country'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 15:33:30 +01:00
|
|
|
// office location goes into an address block
|
|
|
|
if ($record['office-location'])
|
|
|
|
$object['address'][] = array('type' => 'office', 'locality' => $record['office-location']);
|
|
|
|
|
|
|
|
// merge initials into nickname
|
|
|
|
if ($record['initials'])
|
|
|
|
$object['nickname'] = trim($object['nickname'] . ', ' . $record['initials'], ', ');
|
|
|
|
|
2012-03-06 09:58:01 +01:00
|
|
|
// remove empty fields
|
|
|
|
$this->data = array_filter($object);
|
|
|
|
}
|
2012-03-20 23:51:43 +01:00
|
|
|
|
2012-03-21 15:33:30 +01:00
|
|
|
/**
|
|
|
|
* Helper method to copy contents of an Address vector to the contact data object
|
|
|
|
*/
|
|
|
|
private function read_addresses($addresses, &$object, $type = null)
|
|
|
|
{
|
|
|
|
$adrtypes = array_flip($this->addresstypes);
|
|
|
|
|
|
|
|
for ($i=0; $i < $addresses->size(); $i++) {
|
|
|
|
$adr = $addresses->get($i);
|
|
|
|
$object['address'][] = array(
|
|
|
|
'type' => $type ? $type : ($adrtypes[$adr->types()] ? $adrtypes[$adr->types()] : ''), /*$adr->label()),*/
|
|
|
|
'street' => $adr->street(),
|
|
|
|
'code' => $adr->code(),
|
|
|
|
'locality' => $adr->locality(),
|
|
|
|
'region' => $adr->region(),
|
|
|
|
'country' => $adr->country()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-20 23:51:43 +01:00
|
|
|
/**
|
|
|
|
* Helper method to map contents of a Related vector to the contact data object
|
|
|
|
*/
|
|
|
|
private function read_relateds($rels, &$object)
|
|
|
|
{
|
|
|
|
$typemap = array_flip($this->relatedmap);
|
|
|
|
|
|
|
|
for ($i=0; $i < $rels->size(); $i++) {
|
|
|
|
$rel = $rels->get($i);
|
|
|
|
if ($rel->type() != Related::Text) // we can't handle UID relations yet
|
|
|
|
continue;
|
|
|
|
|
|
|
|
$types = $rel->relationTypes();
|
|
|
|
foreach ($typemap as $t => $field) {
|
|
|
|
if ($types & $t) {
|
|
|
|
$object[$field][] = $rel->text();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-06 09:58:01 +01:00
|
|
|
}
|