|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace garethp\ews; |
|
4
|
|
|
|
|
5
|
|
|
use garethp\ews\API\Type; |
|
6
|
|
|
|
|
7
|
|
|
class ContactsAPI extends API |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var Type\FolderIdType |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $folderId; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @return Type\FolderIdType |
|
16
|
|
|
*/ |
|
17
|
|
|
public function getFolderId() |
|
18
|
|
|
{ |
|
19
|
|
|
if (!$this->folderId) { |
|
20
|
|
|
$this->folderId = $this->getFolderByDistinguishedId('contacts')->getFolderId(); |
|
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
return $this->folderId; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param Type\FolderIdType $folderId |
|
28
|
|
|
*/ |
|
29
|
|
|
public function setFolderId($folderId) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->folderId = $folderId; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param Type\FolderIdType $folderId |
|
36
|
|
|
* @param array $options |
|
37
|
|
|
* @return Type\ContactItemType[] |
|
38
|
|
|
*/ |
|
39
|
|
View Code Duplication |
public function getContacts($folderId = null, $options = array()) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
if (!$folderId) { |
|
42
|
|
|
$folderId = $this->getFolderId(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$request = array( |
|
46
|
|
|
'Traversal' => 'Shallow', |
|
47
|
|
|
'ItemShape' => array( |
|
48
|
|
|
'BaseShape' => 'AllProperties' |
|
49
|
|
|
), |
|
50
|
|
|
'ParentFolderIds' => array( |
|
51
|
|
|
'FolderId' => $folderId->toXmlObject() |
|
52
|
|
|
) |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
$request = array_replace_recursive($request, $options); |
|
56
|
|
|
|
|
57
|
|
|
$request = Type::buildFromArray($request); |
|
58
|
|
|
|
|
59
|
|
|
return $this->getClient()->FindItem($request); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param Type\ItemIdType $itemId |
|
64
|
|
|
* @return Type\ContactItemType |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getContact($itemId) |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->getItem($itemId); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param $contacts |
|
73
|
|
|
* @param array $options |
|
74
|
|
|
* @return Type\ItemIdType[] |
|
75
|
|
|
*/ |
|
76
|
|
View Code Duplication |
public function createContacts($contacts, $options = array()) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
$request = array('Contact' => $contacts); |
|
79
|
|
|
|
|
80
|
|
|
$defaultOptions = array( |
|
81
|
|
|
'MessageDisposition' => 'SaveOnly', |
|
82
|
|
|
'SavedItemFolderId' => array('FolderId' => $this->getFolderId()->toArray()) |
|
83
|
|
|
); |
|
84
|
|
|
$options = array_replace_recursive($defaultOptions, $options); |
|
85
|
|
|
|
|
86
|
|
|
$result = $this->createItems($request, $options); |
|
87
|
|
|
|
|
88
|
|
|
if (!is_array($result)) { |
|
89
|
|
|
$result = array($result); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $result; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
View Code Duplication |
public function updateContactItem(Type\ItemIdType $itemId, $changes) |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
|
|
//Create the request |
|
98
|
|
|
$request = array( |
|
99
|
|
|
'ItemChange' => array( |
|
100
|
|
|
'ItemId' => $itemId->toArray(), |
|
101
|
|
|
'Updates' => API\ItemUpdateBuilder::buildUpdateItemChanges('Contact', 'contacts', $changes) |
|
102
|
|
|
) |
|
103
|
|
|
); |
|
104
|
|
|
|
|
105
|
|
|
$options = array(); |
|
106
|
|
|
|
|
107
|
|
|
$items = $this->updateItems($request, $options); |
|
108
|
|
|
|
|
109
|
|
|
if (!is_array($items)) { |
|
110
|
|
|
$items = array($items); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $items; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: