-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkyStaff.php
577 lines (521 loc) · 12.1 KB
/
kyStaff.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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
<?php
/**
* Kayako Staff object.
*
* @author Tomasz Sawicki (https://github.com/Furgas)
* @link http://wiki.kayako.com/display/DEV/REST+-+Staff
* @since Kayako version 4.01.204
* @package Object\Staff
*
* @noinspection PhpDocSignatureInspection
*/
class kyStaff extends kyObjectBase
{
protected static $controller = '/Base/Staff';
protected static $object_xml_name = 'staff';
/**
* Staff identifier.
* @apiField
* @var int
*/
protected $id;
/**
* Staff group identifier.
* @apiField required_create=true
* @var int
*/
protected $staff_group_id;
/**
* Staff first name.
* @apiField required=true
* @var string
*/
protected $first_name;
/**
* Staff last name.
* @apiField required=true
* @var string
*/
protected $last_name;
/**
* Staff full name.
* @apiField
* @var string
*/
protected $full_name;
/**
* Staff username (login).
* @apiField required_create=true
* @var string
*/
protected $user_name;
/**
* Staff e-mail.
* @apiField required_create=true
* @var string
*/
protected $email;
/**
* Staff designation.
* @apiField
* @var string
*/
protected $designation;
/**
* Staff livechat greeting message.
* @apiField
* @var string
*/
protected $greeting;
/**
* Staff signature appended to posts.
* @apiField
* @var string
*/
protected $signature;
/**
* Staff mobile number.
* @apiField
* @var string
*/
protected $mobile_number;
/**
* Is this staff enabled.
* @apiField
* @var bool
*/
protected $is_enabled = true;
/**
* Staff timezone.
* @apiField
* @var string
*/
protected $timezone = 'GMT';
/**
* Is Daylight Saving Time enabled.
* @apiField
* @var bool
*/
protected $enable_dst = false;
/**
* Staff password.
* @apiField required_create=true
* @var string
*/
protected $password;
/**
* Staff group.
* @var kyStaffGroup
*/
private $staff_group = null;
protected function parseData($data)
{
$this->id = intval($data['id']);
$this->staff_group_id = ky_assure_positive_int($data['staffgroupid']);
$this->first_name = $data['firstname'];
$this->last_name = $data['lastname'];
$this->full_name = $data['fullname'];
$this->user_name = $data['username'];
$this->email = $data['email'];
$this->designation = $data['designation'];
$this->greeting = $data['greeting'];
$this->mobile_number = $data['mobilenumber'];
$this->is_enabled = ky_assure_bool($data['isenabled']);
$this->timezone = $data['timezone'];
$this->enable_dst = ky_assure_bool($data['enabledst']);
}
public function buildData($create)
{
$this->checkRequiredAPIFields($create);
$data = array();
$data['staffgroupid'] = $this->staff_group_id;
$data['firstname'] = $this->first_name;
$data['lastname'] = $this->last_name;
$data['username'] = $this->user_name;
$data['email'] = $this->email;
$data['designation'] = $this->designation;
$data['greeting'] = $this->greeting;
if (strlen($this->signature) > 0) {
$data['staffsignature'] = $this->signature;
}
$data['mobilenumber'] = $this->mobile_number;
$data['isenabled'] = $this->is_enabled ? 1 : 0;
$data['timezone'] = $this->timezone;
$data['enabledst'] = $this->enable_dst ? 1 : 0;
if (strlen($this->password) > 0) {
$data['password'] = $this->password;
}
return $data;
}
public function toString()
{
return sprintf("%s (username: %s, email: %s)", $this->getFullName(), $this->getUserName(), $this->getEmail());
}
public function getId($complete = false)
{
return $complete ? array($this->id) : $this->id;
}
/**
* Returns staff group identifier of the staff user.
*
* @return int
* @filterBy
* @orderBy
*/
public function getStaffGroupId()
{
return $this->staff_group_id;
}
/**
* Sets staff group identifier for the staff user.
*
* @param int $staff_group_id Staff group identifier.
* @return kyStaff
*/
public function setStaffGroupId($staff_group_id)
{
$this->staff_group_id = ky_assure_positive_int($staff_group_id);
$this->staff_group = null;
return $this;
}
/**
* Returns staff group of the staff user.
* Result is cached until the end of script.
*
* @param bool $reload True to reload data from server. False to use the cached value (if present).
* @return kyStaffGroup
*/
public function getStaffGroup($reload = false)
{
if ($this->staff_group !== null && !$reload) {
return $this->staff_group;
}
if ($this->staff_group_id === null || $this->staff_group_id <= 0) {
return null;
}
$this->staff_group = kyStaffGroup::get($this->staff_group_id);
return $this->staff_group;
}
/**
* Sets staff group for the staff user.
*
* @param kyStaffGroup $staff_group Staff group object.
* @return kyStaff
*/
public function setStaffGroup($staff_group)
{
$this->staff_group = ky_assure_object($staff_group, 'kyStaffGroup');
$this->staff_group_id = $this->staff_group !== null ? $staff_group->getId() : null;
return $this;
}
/**
* Returns first name of the staff user.
*
* @return string
* @filterBy
* @orderBy
*/
public function getFirstName()
{
return $this->first_name;
}
/**
* Sets first name of the staff user.
*
* @param string $first_name First name of the staff user.
* @return kyStaff
*/
public function setFirstName($first_name)
{
$this->first_name = ky_assure_string($first_name);
return $this;
}
/**
* Returns last name of the staff user.
*
* @return string
* @filterBy
* @orderBy
*/
public function getLastName()
{
return $this->last_name;
}
/**
* Sets last name of the staff user.
*
* @param string $last_name Last name of the staff user.
* @return kyStaff
*/
public function setLastName($last_name)
{
$this->last_name = ky_assure_string($last_name);
return $this;
}
/**
* Returns full name of the staff user.
*
* @return string
* @filterBy
* @orderBy
*/
public function getFullName()
{
return $this->full_name;
}
/**
* Returns login username of the staff user.
*
* @return string
* @filterBy
* @orderBy
*/
public function getUserName()
{
return $this->user_name;
}
/**
* Sets login username of the staff user.
*
* @param string $user_name Login username of the staff user.
* @return kyStaff
*/
public function setUserName($user_name)
{
$this->user_name = ky_assure_string($user_name);
return $this;
}
/**
* Returns e-mail address of the staff user.
*
* @return string
* @filterBy
* @orderBy
*/
public function getEmail()
{
return $this->email;
}
/**
* Sets e-mail address of the staff user.
*
* @param string $email E-mail address of the staff user.
* @return kyStaff
*/
public function setEmail($email)
{
$this->email = ky_assure_string($email);
return $this;
}
/**
* Returns designation of the staff user.
*
* @return string
* @filterBy
* @orderBy
*/
public function getDesignation()
{
return $this->designation;
}
/**
* Sets designation of the staff user.
*
* @param string $designation Designation of the staff user.
* @return kyStaff
*/
public function setDesignation($designation)
{
$this->designation = ky_assure_string($designation);
return $this;
}
/**
* Returns default greeting message when the staff user accepts a live chat request.
*
* @return string
* @filterBy
*/
public function getGreeting()
{
return $this->greeting;
}
/**
* Sets default greeting message when the staff user accepts a live chat request.
*
* @param string $greeting Default greeting message when the staff user accepts a live chat request.
* @return kyStaff
*/
public function setGreeting($greeting)
{
$this->greeting = ky_assure_string($greeting);
return $this;
}
/**
* Returns signature that will be appended to each reply made by the staff user.
* The value is not available when the object was fetched from the server.
*
* @return string
*/
public function getSignature()
{
return $this->signature;
}
/**
* Sets signature that wil be appended to each reply made by the staff user.
*
* @param string $signature Signature that will be appended to each reply made by the staff user.
* @return kyStaff
*/
public function setSignature($signature)
{
$this->signature = ky_assure_string($signature);
return $this;
}
/**
* Returns mobile number of the staff user.
*
* @return string
* @filterBy
*/
public function getMobileNumber()
{
return $this->mobile_number;
}
/**
* Sets mobile number of the staff user.
*
* @param string $mobile_number Mobile number of the staff user.
* @return kyStaff
*/
public function setMobileNumber($mobile_number)
{
$this->mobile_number = ky_assure_string($mobile_number);
return $this;
}
/**
* Returns whether the staff user is enabled.
*
* @return bool
* @filterBy
* @orderBy
*/
public function getIsEnabled()
{
return $this->is_enabled;
}
/**
* Sets whether the staff user is enabled.
* True is the default value when creating new staff user.
*
* @param bool $is_enabled True to enable the staff user. False to disable.
* @return kyStaff
*/
public function setIsEnabled($is_enabled)
{
$this->is_enabled = ky_assure_bool($is_enabled);
return $this;
}
/**
* Returns timezone of the staff user.
*
* @return string
*/
public function getTimezone()
{
return $this->timezone;
}
/**
* Sets timezone of the staff user.
*
* @param string $timezone Timezone of the staff user.
* @return kyStaff
* @filterBy
*/
public function setTimezone($timezone)
{
$this->timezone = ky_assure_string($timezone);
return $this;
}
/**
* Returns whether Daylight Saving Time is enabled for the staff user.
*
* @return bool
* @filterBy
*/
public function getEnableDST()
{
return $this->enable_dst;
}
/**
* Sets whether Daylight Saving Time is enabled for the staff user.
* True is the default value when creating new staff user.
*
* @param bool $enable_dst True to enable Daylight Saving Time for the staff user. False to disable.
* @return kyStaff
*/
public function setEnableDST($enable_dst)
{
$this->enable_dst = ky_assure_bool($enable_dst);
return $this;
}
/**
* Sets password for the staff user.
*
* @param string $password Password for the staff user.
* @return kyStaff
*/
public function setPassword($password)
{
$this->password = ky_assure_string($password);
return $this;
}
/**
* Creates new staff user.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @param string $first_name First name of new staff user.
* @param string $last_name Last name of new staff user.
* @param string $user_name Login username of new staff user.
* @param string $email E-mail address of new staff user.
* @param kyStaffGroup $staff_group Staff group of new staff user.
* @param string $password Password for new staff user.
* @return kyStaff
*/
public static function createNew()
{
list($first_name, $last_name, $user_name, $email, $staff_group, $password) = func_get_args();
$new_staff = new kyStaff();
$new_staff->setFirstName($first_name);
$new_staff->setLastName($last_name);
$new_staff->setUserName($user_name);
$new_staff->setEmail($email);
$new_staff->setStaffGroup($staff_group);
$new_staff->setPassword($password);
return $new_staff;
}
/**
* Creates new ticket with this staff user as the author.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @param kyDepartment $department Department where the ticket will be created.
* @param string $contents Contents of the first post.
* @param string $subject Subject of the ticket.
* @return kyTicket
*/
public function newTicket(kyDepartment $department, $contents, $subject)
{
return kyTicket::createNew($department, $this, $contents, $subject);
}
/**
* Creates a news item with this staff user as the author.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @param string $subject Subject of news item.
* @param string $contents Contents of news item.
* @return kyNewsItem
*/
public function newNewsItem($subject, $contents)
{
return kyNewsItem::createNew($subject, $contents, $this);
}
}