Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F8199064
kolab_sync_data_contacts.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
kolab_sync_data_contacts.php
View Options
<?php
/**
*
*/
class
kolab_sync_data_contacts
extends
kolab_sync_data
{
const
MODEL
=
'Syncroton_Model_Contact'
;
/**
* Mapping from ActiveSync Contacts namespace fields
*/
protected
$mapping
=
array
(
'Anniversary'
=>
'anniversary'
,
'AssistantName'
=>
'assistant:0'
,
//'AssistnamePhoneNumber' => 'assistnamephonenumber',
'Birthday'
=>
'birthday'
,
'Body'
=>
'notes'
,
//'BodySize' => 'bodysize',
//'BodyTruncated' => 'bodytruncated',
//'Business2PhoneNumber' => 'business2phonenumber',
'BusinessCity'
=>
'address.work.locality'
,
'BusinessCountry'
=>
'address.work.country'
,
'BusinessPostalCode'
=>
'address.work.code'
,
'BusinessState'
=>
'address.work.region'
,
'BusinessStreet'
=>
'address.work.street'
,
'BusinessFaxNumber'
=>
'phone.workfax.number'
,
'BusinessPhoneNumber'
=>
'phone.work.number'
,
'CarPhoneNumber'
=>
'phone.car.number'
,
//'Categories' => 'categories',
//'Category' => 'category',
'Children'
=>
'children'
,
//'Child' => 'child',
'CompanyName'
=>
'organization'
,
'Department'
=>
'department'
,
'Email1Address'
=>
'email:0'
,
'Email2Address'
=>
'email:1'
,
'Email3Address'
=>
'email:2'
,
//'FileAs' => 'fileas', //@TODO: ?
'FirstName'
=>
'firstname'
,
//'Home2PhoneNumber' => 'home2phonenumber',
'HomeAddressCity'
=>
'address.home.locality'
,
'HomeAddressCountry'
=>
'address.home.country'
,
'HomeAddressPostalCode'
=>
'address.home.code'
,
'HomeAddressState'
=>
'address.home.region'
,
'HomeAddressStreet'
=>
'address.home.street'
,
'HomeFaxNumber'
=>
'phone.homefax.number'
,
'HomePhoneNumber'
=>
'phone.home.number'
,
'JobTitle'
=>
'jobtitle'
,
'LastName'
=>
'surname'
,
'MiddleName'
=>
'middlename'
,
'MobilePhoneNumber'
=>
'phone.mobile.number'
,
//'OfficeLocation' => 'officelocation',
'OtherCity'
=>
'address.office.locality'
,
'OtherCountry'
=>
'address.office.country'
,
'OtherPostalCode'
=>
'address.office.code'
,
'OtherState'
=>
'address.office.region'
,
'OtherStreet'
=>
'address.office.street'
,
'PagerNumber'
=>
'phone.pager.number'
,
//'RadioPhoneNumber' => 'radiophonenumber',
'Spouse'
=>
'spouse'
,
'Suffix'
=>
'suffix'
,
'Title'
=>
'prefix'
,
'WebPage'
=>
'website.homepage.url'
,
//'YomiCompanyName' => 'yomicompanyname',
//'YomiFirstName' => 'yomifirstname',
//'YomiLastName' => 'yomilastname',
//'Rtf' => 'rtf',
'Picture'
=>
'photo'
,
// Mapping from ActiveSync Contacts2 namespace fields
//'CustomerId' => 'customerid',
//'GovernmentId' => 'governmentid',
'IMAddress'
=>
'im:0'
,
'IMAddress2'
=>
'im:1'
,
'IMAddress3'
=>
'im:2'
,
'ManagerName'
=>
'manager:0'
,
//'CompanyMainPhone' => 'companymainphone',
//'AccountName' => 'accountname',
'NickName'
=>
'nickname'
,
//'MMS' => 'mms',
);
/**
* Kolab object type
*
* @var string
*/
protected
$modelName
=
'contact'
;
/**
* Type of the default folder
*
* @var int
*/
protected
$defaultFolderType
=
Syncroton_Command_FolderSync
::
FOLDERTYPE_CONTACT
;
/**
* Default container for new entries
*
* @var string
*/
protected
$defaultFolder
=
'Contacts'
;
/**
* Type of user created folders
*
* @var int
*/
protected
$folderType
=
Syncroton_Command_FolderSync
::
FOLDERTYPE_CONTACT_USER_CREATED
;
/**
* Default namespace
*
* @var string
*/
protected
$defaultNS
=
'Contacts'
;
/**
* Field to sort search results by
*
* @var string
*/
protected
$sortField
=
'n_fileas'
;
/**
* Creates model object
*
* @param Syncroton_Model_SyncCollection $collection Collection data
* @param string $serverId Local entry identifier
*/
public
function
getEntry
(
Syncroton_Model_SyncCollection
$collection
,
$serverId
)
{
$data
=
is_array
(
$serverId
)
?
$serverId
:
$this
->
getObject
(
$collection
->
collectionId
,
$serverId
);
$result
=
array
();
// Contacts namespace fields
foreach
(
$this
->
mapping
as
$key
=>
$name
)
{
$value
=
$this
->
getKolabDataItem
(
$data
,
$name
);
switch
(
$name
)
{
case
'photo'
:
if
(
$value
)
{
// ActiveSync limits photo size to 48KB (of base64 encoded string)
if
(
strlen
(
$value
)
*
1.33
>
48
*
1024
)
{
continue
;
}
}
break
;
case
'birthday'
:
case
'anniversary'
:
$value
=
self
::
date_from_kolab
(
$value
);
break
;
case
'notes'
:
$value
=
$this
->
setBody
(
$value
);
break
;
}
if
(
empty
(
$value
)
||
is_array
(
$value
))
{
continue
;
}
$result
[
$key
]
=
$value
;
}
return
new
Syncroton_Model_Contact
(
$result
);
}
/**
* convert contact from xml to libkolab array
*
* @param Syncroton_Model_IEntry $data Contact to convert
* @param string $folderId Folder identifier
* @param array $entry Existing entry
*
* @return array Kolab object array
*/
public
function
toKolab
(
Syncroton_Model_IEntry
$data
,
$folderId
,
$entry
=
null
)
{
$contact
=
!
empty
(
$entry
)
?
$entry
:
array
();
// Contacts namespace fields
foreach
(
$this
->
mapping
as
$key
=>
$name
)
{
$value
=
$data
->
$key
;
switch
(
$name
)
{
case
'address.work.street'
:
if
(
strtolower
(
$this
->
device
->
devicetype
)
==
'palm'
)
{
// palm pre sends the whole address in the <Contacts:BusinessStreet> tag
$value
=
null
;
}
break
;
case
'email:0'
:
case
'email:1'
:
case
'email:2'
:
// android send email address as
// Lars Kneschke <l.kneschke@metaways.de>
if
(
preg_match
(
'/(.*)<(.+@[^@]+)>/'
,
$value
,
$matches
))
{
$value
=
trim
(
$matches
[
2
]);
}
break
;
case
'website.homepage.url'
:
// remove facebook urls
if
(
preg_match
(
'/^fb:
\/\/
/'
,
$value
))
{
$value
=
null
;
}
break
;
case
'notes'
:
$value
=
$this
->
getBody
(
$value
);
break
;
}
$this
->
setKolabDataItem
(
$contact
,
$name
,
$value
);
}
return
$contact
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Jul 8, 9:56 PM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1052094
Default Alt Text
kolab_sync_data_contacts.php (7 KB)
Attached To
Mode
R4 syncroton
Attached
Detach File
Event Timeline
Log In to Comment