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