-
Notifications
You must be signed in to change notification settings - Fork 5
/
IndividualClient.class.php
357 lines (284 loc) · 8.88 KB
/
IndividualClient.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
namespace SimClient;
/**
* @file
* Implements the Selligent Individual API.
*/
require_once('SimProxy.class.php');
/**
* This class is used to query the Selligent Individual API.
* Set the properties for your query and execute the API function you need.
*/
class IndividualClient extends SimProxy{
/**
* The list you want to query.
* @var int
*/
private $lid = '';
/**
* The filters you like to apply.
* @var array
*/
private $filter = array();
/**
* The maximum amount of values you like to be returned.
* Only applies to the 'ByFilter'-functions.
* @var int
*/
private $maxcount = 10;
/**
* A constraint you like to add (see Selligent documentation).
* Only applies to the 'ByConstraint'-functions.
* @var string
*/
private $constraint = '';
/**
* The user ID you would like to retrieve.
* Only applies to the 'ById'-function.
* @var int
*/
private $uid = '';
/**
* The properties you like to set.
* @var array
*/
private $properties = array();
/**
* The campaign gate you like to use (see Selligent documentation).
* @var int
*/
private $gate = '';
/**
* The XML you want to use.
* @var string (xml)
*/
private $xml = '';
private $proxy;
public function setList($lid) {
$this->lid = $lid;
return $this;
}
public function setMaxcount($maxcount) {
$this->maxcount = $maxcount;
return $this;
}
public function setConstraint($constraint) {
$this->constraint = $constraint;
return $this;
}
public function setUserId($uid) {
$this->uid = $uid;
return $this;
}
public function setGate($gate) {
$this->gate = $gate;
return $this;
}
public function setXml($xml) {
$this->xml = $xml;
return $this;
}
public function addProperty($key, $value) {
$this->properties[] = array('Key' => $key, 'Value' => $value);
return $this;
}
public function addFilter($key, $value) {
$this->filter[] = array('Key' => $key, 'Value' => $value);
return $this;
}
/**
* @return ResultIDs Array containing the users retrieved
* @return ErrorStr Error description (only when process fails)
*/
public function getUsersByFilter() {
if ($this->lid == '') throw new \Exception('Not all properties are set for this method.');
$input = array();
$input['List'] = $this->lid;
$input['Filter'] = $this->filter;
$input['MaxCount'] = $this->maxcount;
$result = $this->call('GetUsersByFilter', $input);
if (isset($result->ErrorStr) && $result->ErrorStr != '') {
return array();
}
if (isset($result->ResultIDs->int)) {
$result = $result->ResultIDs->int;
}
else {
$result = array();
}
return $result;
}
/**
* @return ResultSet Array containing the user information
* @return ErrorStr Error description (only when process fails)
*/
public function getUserByFilter() {
if ($this->lid == '') throw new \Exception('Not all properties are set for this method.');
$input = array();
$input['List'] = $this->lid;
$input['Filter'] = $this->filter;
$result = $this->call('GetUserByFilter', $input);
if (isset($result->ErrorStr) && $result->GetUserByFilterResult == 10005) {
return array();
} else {
if ($result->ResultSet)
return $this->fetchUserResultSet($result->ResultSet->Property);
}
}
/**
* @return ResultIDs Array containing the users retrieved
* @return ErrorStr Error description (only when process fails)
*/
public function getUsersByConstraint() {
if ($this->lid == '') throw new \Exception('Not all properties are set for this method.');
$input = array();
$input['List'] = $this->lid;
$input['Constraint'] = $this->constraint;
$input['MaxCount'] = $this->maxcount;
$result = $this->call('GetUsersByConstraint', $input);
if (isset($result->ErrorStr) && $result->ErrorStr != '') {
return array();
}
if (isset($result->ResultIDs->int)) {
$result = $result->ResultIDs->int;
}
else {
$result = array();
}
return $result;
}
/**
* @return ResultSet Array containing the user information
* @return ErrorStr Error description (only when process fails)
*/
public function getUserByConstraint() {
if ($this->lid == '') throw new \Exception('Not all properties are set for this method.');
$input = array();
$input['List'] = $this->lid;
$input['Constraint'] = $this->constraint;
$result = $this->call('GetUserByConstraint', $input);
if (isset($result->ErrorStr) && $result->ErrorStr != '') {
return array();
}
if ($result) {
$result = $this->fetchUserResultSet($result->ResultSet->Property);
} else {
$result = array();
}
return $result;
}
/**
* @return ResultSet Array containing the user information
* @return ErrorStr Error description (only when process fails)
*/
public function getUserById() {
if ($this->lid == '' || $this->uid == '') throw new \Exception('Not all properties are set for this method.');
$input = array();
$input['List'] = $this->lid;
$input['UserID'] = $this->uid;
$result = $this->call('GetUserById', $input);
if (isset($result->ErrorStr) && $result->ErrorStr != '') {
return array();
}
if ($result) {
return $this->fetchUserResultSet($result->ResultSet->Property);
} else {
return array();
}
return $result;
}
/**
* @return ID ID of the newly created user ErrorStr
* @return Error description (only when process fails)
*/
public function createUser() {
if ($this->lid == '' || sizeof($this->properties) == 0) throw new \Exception('Not all properties are set for this method.');
$input['List'] = $this->lid;
$input['Changes'] = $this->properties;
$result = $this->call('CreateUser', $input);
$result = $result->ID;
return $result;
}
/**
* @return ID ID of the newly created user ErrorStr
* @return Error description (only when process fails)
*/
public function updateUser() {
if ($this->lid == '' || sizeof($this->properties) == 0 || $this->uid == '') throw new \Exception('Not all properties are set for this method.');
$input['List'] = $this->lid;
$input['Changes'] = $this->properties;
$input['UserID'] = $this->uid;
$result = $this->call('UpdateUser', $input);
return $result;
}
/**
* @return HashCode Hashcode used to access a module by doing a HTTP call on the SIM WebAgent
* @return ErrorStr Error description (only when process fails)
*/
public function retrieveHashForUser() {
if ($this->lid == '' || $this->gate == '' || $this->uid == '') throw new \Exception('Not all properties are set for this method.');
$input['GateName'] = $this->gate;
$input['List'] = $this->lid;
$input['UserID'] = $this->uid;
$result = $this->call('RetrieveHashForUser', $input);
$result = $result->HashCode;
return $result;
}
/**
* @return ErrorStr Error description (only when process fails)
*/
public function triggerCampaign() {
if ($this->gate == '' || sizeof($this->properties) == 0) throw new \Exception('Not all properties are set for this method.');
$input['GateName'] = $this->gate;
$input['InputData'] = $this->properties;
$result = $this->call('TriggerCampaign', $input);
return $result;
}
/**
* @return ErrorStr Error description (only when process fails)
*/
public function triggerCampaignByXML() {
if ($this->lid == '' || $this->gate == '' || $this->uid == '' || sizeof($this->properties) == 0) \Exception('Not all properties are set for this method.');
$input['GateName'] = $this->gate;
$input['Xml'] = $this->data;
$result = $this->call('TriggerCampaignByXml', $input);
return $result;
}
public function triggerCampaignForUser() {
if ($this->lid == '' || $this->gate == '' || $this->uid == '' || sizeof($this->properties) == 0) throw new \Exception('Not all properties are set for this method.');
$input['GateName'] = $this->gate;
$input['List'] = $this->lid;
$input['InputData'] = $this->properties;
$input['UserID'] = $this->uid;
$result = $this->call('TriggerCampaignForUser', $input);
return $result;
}
/**
* @return string the current system status
*/
public function getSystemStatus() {
$result = $this->call('GetSystemStatus', NULL);
if (isset($result->GetSystemStatusResult)) {
return $result->GetSystemStatusResult;
} else {
return 'unable to retrieve status';
}
}
/**
* Overrides abstract function getSoapUrl
*/
protected function getSoapUrl() {
return $this->individualURL;
}
/**
* Helper function to fetch the Result URL
* @param array $resultSet
*/
private function fetchUserResultSet($resultSet) {
$return = array();
foreach ($resultSet as $result) {
$return[$result->Key] = $result->Value;
}
return $return;
}
}