forked from Furgas/php-api-library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkyUserOrganization.php
executable file
·490 lines (434 loc) · 10.2 KB
/
kyUserOrganization.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<?php
/**
* Kayako UserOrganization object.
*
* @author Tomasz Sawicki (https://github.com/Furgas)
* @link http://wiki.kayako.com/display/DEV/REST+-+UserOrganization
* @since Kayako version 4.01.204
* @package Object\User
*/
class kyUserOrganization extends kyObjectBase {
const TYPE_RESTRICTED = 'restricted';
const TYPE_SHARED = 'shared';
static protected $controller = '/Base/UserOrganization';
static protected $object_xml_name = 'userorganization';
/**
* User organization identifier.
* @apiField
* @var int
*/
protected $id;
/**
* User organization name.
* @apiField required=true
* @var string
*/
protected $name;
/**
* User organization type.
*
* @see kyUserOrganization::TYPE constants.
*
* @apiField name=organizationtype required_create=true
* @var string
*/
protected $type = self::TYPE_RESTRICTED;
/**
* User organization address.
* @apiField
* @var string
*/
protected $address;
/**
* User organization city.
* @apiField
* @var string
*/
protected $city;
/**
* User organization state.
* @apiField
* @var string
*/
protected $state;
/**
* User organization postal code.
* @apiField
* @var string
*/
protected $postal_code;
/**
* User organization country.
* @apiField
* @var string
*/
protected $country;
/**
* User organization phone number.
* @apiField
* @var string
*/
protected $phone;
/**
* User organization FAX number.
* @apiField
* @var string
*/
protected $fax;
/**
* User organization website URL.
* @apiField
* @var string
*/
protected $website;
/**
* Timestamp of when the user organization was created.
* @apiField
* @var int
*/
protected $dateline;
/**
* Timestamp of when the user organization was last updated.
* @apiField
* @var int
*/
protected $last_update;
/**
* Identifier of Service Level Agreement plan associated to this user organization.
* @apiField
* @var int
*/
protected $sla_plan_id;
/**
* Timestamp of when the Service Level Agreement plan associated to this user organization will expire.
* @apiField
* @var int
*/
protected $sla_plan_expiry;
protected function parseData($data) {
$this->id = intval($data['id']);
$this->name = $data['name'];
$this->type = $data['organizationtype'];
$this->address = $data['address'];
$this->city = $data['city'];
$this->state = $data['state'];
$this->postal_code = $data['postalcode'];
$this->country = $data['country'];
$this->phone = $data['phone'];
$this->fax = $data['fax'];
$this->website = $data['website'];
$this->dateline = ky_assure_positive_int($data['dateline']);
$this->last_update = ky_assure_positive_int($data['lastupdate']);
$this->sla_plan_id = ky_assure_positive_int($data['slaplanid']);
$this->sla_plan_expiry = ky_assure_positive_int($data['slaplanexpiry']);
}
public function buildData($create) {
$this->checkRequiredAPIFields($create);
$data = array();
$data['name'] = $this->name;
$data['organizationtype'] = $this->type;
$data['address'] = $this->address;
$data['city'] = $this->city;
$data['state'] = $this->state;
$data['postalcode'] = $this->postal_code;
$data['country'] = $this->country;
$data['phone'] = $this->phone;
$data['fax'] = $this->fax;
$data['website'] = $this->website;
$data['slaplanid'] = $this->sla_plan_id;
$data['slaplanexpiry'] = $this->sla_plan_expiry !== null ? $this->sla_plan_expiry : 0;
return $data;
}
public function toString() {
return sprintf("%s (type: %s)", $this->getName(), $this->getType());
}
public function getId($complete = false) {
return $complete ? array($this->id) : $this->id;
}
/**
* Returns user organization name.
*
* @returns string
* @filterBy
* @orderBy
*/
public function getName() {
return $this->name;
}
/**
* Sets user organization name.
*
* @param string $name User organization name.
* @return kyUserOrganization
*/
public function setName($name) {
$this->name = ky_assure_string($name);
return $this;
}
/**
* Returns user organization type.
*
* @see kyUserOrganization::TYPE constans.
*
* @returns string
* @filterBy
* @orderBy
*/
public function getType() {
return $this->type;
}
/**
* Sets user organization type.
*
* @see kyUserOrganization::TYPE constans.
*
* @param string $type User organization type
* @return kyUserOrganization
*/
public function setType($type) {
$this->type = ky_assure_constant($type, $this, 'TYPE');
return $this;
}
/**
* Returns user organization address.
*
* @returns string
* @filterBy
* @orderBy
*/
public function getAddress() {
return $this->address;
}
/**
* Sets user organization address.
*
* @param string $address User organization address.
* @return kyUserOrganization
*/
public function setAddress($address) {
$this->address = ky_assure_string($address);
return $this;
}
/**
* Returns user organization city.
*
* @returns string
* @filterBy
* @orderBy
*/
public function getCity() {
return $this->city;
}
/**
* Sets user organization city.
*
* @param string $city User organization city.
* @return kyUserOrganization
*/
public function setCity($city) {
$this->city = ky_assure_string($city);
return $this;
}
/**
* Returns user organization state.
*
* @returns string
* @filterBy
* @orderBy
*/
public function getState() {
return $this->state;
}
/**
* Sets user organization state.
*
* @param string $state User organization state.
* @return kyUserOrganization
*/
public function setState($state) {
$this->state = ky_assure_string($state);
return $this;
}
/**
* Returns user organization postal code.
*
* @returns string
* @filterBy
* @orderBy
*/
public function getPostalCode() {
return $this->postal_code;
}
/**
* Sets user organization postal code.
*
* @param string $postal_code User organization postal code.
* @return kyUserOrganization
*/
public function setPostalCode($postal_code) {
$this->postal_code = ky_assure_string($postal_code);
return $this;
}
/**
* Returns user organization country.
*
* @returns string
* @filterBy
* @orderBy
*/
public function getCountry() {
return $this->country;
}
/**
* Sets user organization country.
*
* @param string $country User organization country.
* @return kyUserOrganization
*/
public function setCountry($country) {
$this->country = ky_assure_string($country);
return $this;
}
/**
* Returns user organization phone number.
*
* @returns string
* @filterBy
*/
public function getPhone() {
return $this->phone;
}
/**
* Sets user organization phone number.
*
* @param string $phone User organization phone number.
* @return kyUserOrganization
*/
public function setPhone($phone) {
$this->phone = ky_assure_string($phone);
return $this;
}
/**
* Returns user organization FAX number.
*
* @returns string
* @filterBy
*/
public function getFAX() {
return $this->fax;
}
/**
* Sets user organization FAX number.
*
* @param string $fax User organization FAX number.
* @return kyUserOrganization
*/
public function setFAX($fax) {
$this->fax = ky_assure_string($fax);
return $this;
}
/**
* Returns user organization website URL.
*
* @returns string
* @filterBy
*/
public function getWebsite() {
return $this->website;
}
/**
* Sets user organization website URL.
*
* @param string $website User organization website URL.
* @return kyUserOrganization
*/
public function setWebsite($website) {
$this->website = ky_assure_string($website);
return $this;
}
/**
* Returns date and time when the user organization was created.
*
* @see http://www.php.net/manual/en/function.date.php
*
* @param string $format Output format of the date. If null the format set in client configuration is used.
* @return string
* @filterBy
* @orderBy
*/
public function getDateline($format = null) {
if ($this->dateline == null)
return null;
if ($format === null) {
$format = kyConfig::get()->getDatetimeFormat();
}
return date($format, $this->dateline);
}
/**
* Returns date and time when the user organization was last updated.
*
* @see http://www.php.net/manual/en/function.date.php
*
* @param string $format Output format of the date. If null the format set in client configuration is used.
* @return string
* @filterBy
* @orderBy
*/
public function getLastUpdate($format = null) {
if ($this->last_update == null)
return null;
if ($format === null) {
$format = kyConfig::get()->getDatetimeFormat();
}
return date($format, $this->last_update);
}
/**
* Return Service Level Agreement plan assigned to the user organization.
*
* @return int
* @filterBy
*/
public function getSLAPlanId() {
return $this->sla_plan_id;
}
/**
* Sets identifier of the Service Level Agreement plan assigned to the user organization.
*
* @param int $sla_plan_id Service Level Agreement plan identifier.
* @return kyUserOrganization
*/
public function setSLAPlanId($sla_plan_id) {
$this->sla_plan_id = ky_assure_positive_int($sla_plan_id);
return $this;
}
/**
* Returns expiration date of Service Level Agreement plan assignment or null when expiration is disabled.
*
* @see http://www.php.net/manual/en/function.date.php
*
* @param string $format Output format of the date. If null the format set in client configuration is used.
* @return string
* @filterBy
* @orderBy
*/
public function getSLAPlanExpiry($format = null) {
if ($this->sla_plan_expiry == null)
return null;
if ($format === null) {
$format = kyConfig::get()->getDatetimeFormat();
}
return date($format, $this->sla_plan_expiry);
}
/**
* Sets expiration date of Service Level Agreement plan assignment.
*
* @see http://www.php.net/manual/en/function.strtotime.php
*
* @param string|int|null $sla_plan_expiry Date and time when Service Level Agreement plan for this user organization will expire (timestamp or string format understood by PHP strtotime). Null to disable expiration.
* @return kyUserOrganization
*/
public function setSLAPlanExpiry($sla_plan_expiry) {
$this->sla_plan_expiry = is_numeric($sla_plan_expiry) || $sla_plan_expiry === null ? ky_assure_positive_int($sla_plan_expiry) : strtotime($sla_plan_expiry);
return $this;
}
}