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