Merge branch 'master' of http://git.tine20.org/git/Syncope
[tine20] / tine20 / library / Syncope / lib / Syncope / Data / Contacts.php
1 <?php
2
3 /**
4  * Syncope
5  *
6  * @package     Model
7  * @license     http://www.tine20.org/licenses/lgpl.html LGPL Version 3
8  * @copyright   Copyright (c) 2009-2012 Metaways Infosystems GmbH (http://www.metaways.de)
9  * @author      Lars Kneschke <l.kneschke@metaways.de>
10  */
11
12 /**
13  * class to handle ActiveSync Sync command
14  *
15  * @package     Model
16  */
17
18 class Syncope_Data_Contacts extends Syncope_Data_AData
19 {
20     public function appendXML(DOMElement $_domParrent, $_collectionData, $_serverId)
21     {
22         $_domParrent->ownerDocument->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:Contacts', 'uri:Contacts');
23         
24         foreach (Syncope_Data_AData::$entries[get_class($this)][$_collectionData["collectionId"]][$_serverId] as $key => $value) {
25             // don't add empty values
26             if($value === null || $value == '') {
27                 continue;
28             }
29             
30             $node = $_domParrent->ownerDocument->createElementNS('uri:Contacts', $key);
31             $node->appendChild($_domParrent->ownerDocument->createTextNode($value));
32             
33             $_domParrent->appendChild($node);
34         }
35         
36     }
37     
38     public function createEntry($_folderId, SimpleXMLElement $_entry)
39     {
40         $xmlData = $_entry->children('uri:Contacts');
41         
42         $id = sha1(mt_rand(). microtime());
43         
44         Syncope_Data_AData::$entries[get_class($this)][$_folderId][$id] = array(
45             'FirstName' => (string)$xmlData->FirstName, 
46             'LastName'  => (string)$xmlData->LastName
47         );
48         
49         return $id;
50     }
51     
52     public function updateEntry($_folderId, $_serverId, SimpleXMLElement $_entry)
53     {
54         $xmlData = $_entry->children('uri:Contacts');
55         
56         Syncope_Data_AData::$entries[get_class($this)][$_folderId][$_serverId] = array(
57             'FirstName' => (string)$xmlData->FirstName, 
58             'LastName'  => (string)$xmlData->LastName
59         );
60     }        
61     
62     protected function _initData()
63     {
64         /**
65         * used by unit tests only to simulated added folders
66         */
67         if (!isset(Syncope_Data_AData::$folders[get_class($this)])) {
68             Syncope_Data_AData::$folders[get_class($this)] = array(
69                 'addressbookFolderId' => array(
70                     'folderId'    => 'addressbookFolderId',
71                     'parentId'    => null,
72                     'displayName' => 'Default Contacts Folder',
73                     'type'        => Syncope_Command_FolderSync::FOLDERTYPE_CONTACT
74                 ),
75                 'anotherAddressbookFolderId' => array(
76                     'folderId'    => 'anotherAddressbookFolderId',
77                     'parentId'    => null,
78                     'displayName' => 'Another Contacts Folder',
79                     'type'        => Syncope_Command_FolderSync::FOLDERTYPE_CONTACT_USER_CREATED
80                 )
81             );
82         }
83         
84         /**
85          * used by unit tests only to simulated added folders
86          */
87         if (!isset(Syncope_Data_AData::$entries[get_class($this)])) {
88             Syncope_Data_AData::$entries[get_class($this)] = array(
89                 'addressbookFolderId' => array(
90                     'contact1' => array(
91                         'FirstName' => 'Lars', 
92                         'LastName'  => 'Kneschke'
93                     ),
94                     'contact2' => array(
95                         'FirstName' => 'Cornelius', 
96                         'LastName'  => 'Weiß'
97                     ),
98                     'contact3' => array(
99                         'FirstName' => 'Lars', 
100                         'LastName'  => 'Kneschke'
101                     ),
102                     'contact4' => array(
103                         'FirstName' => 'Cornelius', 
104                         'LastName'  => 'Weiß'
105                     ),
106                     'contact5' => array(
107                         'FirstName' => 'Lars', 
108                         'LastName'  => 'Kneschke'
109                     ),
110                     'contact6' => array(
111                         'FirstName' => 'Cornelius', 
112                         'LastName'  => 'Weiß'
113                     ),
114                     'contact7' => array(
115                         'FirstName' => 'Lars', 
116                         'LastName'  => 'Kneschke'
117                     ),
118                     'contact8' => array(
119                         'FirstName' => 'Cornelius', 
120                         'LastName'  => 'Weiß'
121                     ),
122                     'contact9' => array(
123                         'FirstName' => 'Lars', 
124                         'LastName'  => 'Kneschke'
125                     ),
126                     'contact10' => array(
127                         'FirstName' => 'Cornelius', 
128                         'LastName'  => 'Weiß'
129                     )
130                 )
131             );
132         }
133     }
134 }
135