forked from Furgas/php-api-library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkyTroubleshooterCategory.php
executable file
·474 lines (420 loc) · 12.9 KB
/
kyTroubleshooterCategory.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
<?php
/**
* Kayako TroubleshooterCategory object.
*
* @author Saloni Dhall (https://github.com/SaloniDhall)
* @link http://wiki.kayako.com/display/DEV/REST+-+TroubleshooterCategory
* @since Kayako version 4.64.1
* @package Object\TroubleshooterCategory
*
*/
class kyTroubleshooterCategory extends kyObjectBase {
/**
* TroubleshooterCategory type - Global.
* Private TroubleshooterCategory are visible in your end users in the support center and in the staff control panel.
*
* @var int
*/
const CATEGORY_TYPE_GLOBAL = '1';
/**
* TroubleshooterCategory type - Public.
* Public TroubleshooterCategory are visible in both the support center.
*
* @var int
*/
const CATEGORY_TYPE_PUBLIC = '2';
/**
* TroubleshooterCategory type - Private.
* Private TroubleshooterCategory are visible only in Staff CP.
*
* @var int
*/
const CATEGORY_TYPE_PRIVATE = '3';
static protected $controller = '/Troubleshooter/Category';
static protected $object_xml_name = 'troubleshootercategory';
/**
* TroubleshooterCategory identifier.
* @apiField
* @var int
*/
protected $id;
/**
* TroubleshooterCategory title.
* @apiField required=true
* @var string
*/
protected $title;
/**
* TroubleshooterCategory type.
* @apiField required=true
* @var int
*/
protected $category_type;
/**
* TroubleshooterCategory display order
* @apiField required=optional
* @var int
*/
protected $displayorder;
/**
* TroubleshooterCategory description
* @apiField required=true
* @var string
*/
protected $description;
/**
* If this TroubleshooterCategory is visible to specific user groups only
* @see kyTroubleshooterCategory::$user_group_ids
* @var bool
*/
protected $user_visibility_custom;
/**
* User group identifiers this TroubleshooterCategory is visible to.
* @apiField name=usergroupidlist
* @var int[]
*/
protected $user_group_ids;
/**
* If this TroubleshooterCategory is visible to specific staff groups only.
* @see kyTroubleshooterCategory::$staff_group_ids
* @apiField
* @var bool
*/
protected $staff_visibility_custom;
/**
* User group identifiers this TroubleshooterCategory is visible to.
* @apiField name=staffgroupidlist
* @var int[]
*/
protected $staff_group_ids = array();
/**
* TroubleshooterCategory created by which staff Id
* @apiField required=optional
* @var int
*/
protected $staff_id;
/**
* TroubleshooterCategory created by which staff
* @apiField required=optional
* @var int
*/
protected $staff;
protected function parseData($data) {
$this->id = ky_assure_positive_int($data['id']);
$this->title = ky_assure_string($data['title']);
$this->category_type = ky_assure_string($data['categorytype']);
$this->description = ky_assure_string($data['description']);
$this->displayorder = ky_assure_positive_int($data['displayorder']);
if ($this->user_visibility_custom && is_array($data['usergroupidlist'])) {
$this->user_group_ids = array();
if (is_string($data['usergroupidlist'][0]['usergroupid'])) {
$this->user_group_ids[] = intval($data['usergroupidlist'][0]['usergroupid']);
} else {
foreach ($data['usergroupidlist'][0]['usergroupid'] as $user_group_id) {
$this->user_group_ids[] = intval($user_group_id);
}
}
}
$this->staff_visibility_custom = ky_assure_bool($data['staffvisibilitycustom']);
$this->staff_group_ids = array();
if ($this->staff_visibility_custom && is_array($data['staffgroupidlist'])) {
if (is_string($data['staffgroupidlist'][0]['staffgroupid'])) {
$this->staff_group_ids[] = ky_assure_positive_int($data['staffgroupidlist'][0]['staffgroupid']);
} else {
foreach ($data['staffgroupidlist'][0]['staffgroupid'] as $staff_group_id) {
$this->staff_group_ids[] = ky_assure_positive_int($staff_group_id);
}
}
}
$this->staff_id = ky_assure_int($data['staffid']);
}
public function buildData($create) {
$data = array();
$this->buildDataString($data, 'title', $this->title);
$this->buildDataString($data, 'categorytype', $this->category_type);
$this->buildDataString($data, 'description', $this->description);
$this->buildDataNumeric($data, 'displayorder', $this->displayorder);
$this->buildDataBool($data, 'uservisibilitycustom', $this->user_visibility_custom);
if ($this->user_visibility_custom) {
$this->buildDataList($data, 'usergroupidlist', $this->user_group_ids);
}
$this->buildDataBool($data, 'staffvisibilitycustom', $this->staff_visibility_custom);
if ($this->staff_visibility_custom) {
$this->buildDataList($data, 'staffgroupidlist', $this->staff_group_ids);
}
$this->buildDataNumeric($data, 'staffid', $this->staff_id);
return $data;
}
public function toString() {
return sprintf("%s (contents : %s) (category type: %s)", $this->getTitle(), $this->getDescription(), $this->getCategoryType());
}
public function getId($complete = false) {
return $complete ? array($this->id) : $this->id;
}
/**
* Return category type of the TroubleshooterCategory.
*
* @see kyTroubleshooterCategory::CATEGORY_TYPE constants.
*
* @return int
* @filterBy
* @orderBy
*/
public function getCategoryType() {
return $this->category_type;
}
/**
* Sets category type of the TroubleshooterCategory.
*
* @see kyTroubleshooterCategory::CATEGORY_TYPE constants.
*
* @param int $category_type Category type of the TroubleshooterCategory.
* @return kyTroubleshooterCategory
*/
public function setCategoryType($category_type) {
$this->category_type = ky_assure_constant($category_type, $this, 'CATEGORY_TYPE');
return $this;
}
/**
* Returns title of the TroubleshooterCategory.
*
* @return string
* @filterBy
* @orderBy
*/
public function getTitle() {
return $this->title;
}
/**
* Sets title of the TroubleshooterCategory.
*
* @param string $title Title of the TroubleshooterCategory.
* @return kyTroubleshooterCategory
*/
public function setTitle($title) {
$this->title = ky_assure_string($title);
return $this;
}
/**
* Returns description of the TroubleshooterCategory.
*
* @return string
* @filterBy
* @orderBy
*/
public function getDescription() {
return $this->description;
}
/**
* Sets description of the TroubleshooterCategory.
*
* @param int $display_order of the TroubleshooterCategory.
* @return kyTroubleshooterCategory
*/
public function setDescription($description) {
$this->description = ky_assure_string($description);
return $this;
}
/**
* Returns displayorder of the TroubleshooterCategory.
*
* @return int
* @filterBy
* @orderBy
*/
public function getDisplayOrder() {
return $this->displayorder;
}
/**
* Sets displayorder of the TroubleshooterCategory.
*
* @param int $display_order of the TroubleshooterCategory.
* @return kyTroubleshooterCategory
*/
public function setDisplayOrder($display_order) {
$this->displayorder = ky_assure_int($display_order, 0);
return $this;
}
/**
* Gets the staff user, the creator of this TroubleshooterCategory.
*
* @param bool $reload True to reload data from server. False to use the cached value (if present).
* @return kyStaff
*/
public function getStaff($reload = false) {
if ($this->staff !== null && !$reload)
return $this->staff;
if ($this->staff_id === null)
return null;
$this->staff = kyStaff::get($this->staff_id);
return $this->staff;
}
/**
* Sets staff user, the creator of this TroubleshooterCategory.
*
* @param kyStaff $staff Staff user.
* @return kyTroubleshooterCategory
*/
public function setStaff($staff) {
$this->staff = ky_assure_object($staff, 'kyStaff');
$this->staff_id = $this->staff !== null ? $this->staff->getId() : null;
return $this;
}
/**
* Returns true to indicate that visibility of this TroubleshooterCategory is restricted to particular user groups.
* Use getUserGroupIds to get their identifiers or getUserGroups to get the objects.
*
* @return bool
* @filterBy
*/
public function getUserVisibilityCustom() {
return $this->user_visibility_custom;
}
/**
* Sets whether to restrict visibility of this TroubleshooterCategory to particular user groups.
* Use setUserGroupIds to set these groups using identifiers set them using objects.
* Automatically clears user groups when set to false.
*
* @param bool $user_visibility_custom True to restrict visibility of this TroubleshooterCategory to particular user groups. False otherwise.
* @return kyTroubleshooterCategory
*/
public function setUserVisibilityCustom($user_visibility_custom) {
$this->user_visibility_custom = ky_assure_bool($user_visibility_custom);
if ($this->user_visibility_custom === false) {
$this->user_group_ids = array();
}
return $this;
}
/**
* Returns identifiers of user groups that this TroubleshooterCategory will be visible to.
*
* @return array
* @filterBy name=UserGroupId
*/
public function getUserGroupIds() {
return $this->user_group_ids;
}
/**
* Sets user groups (using their identifiers) that this TroubleshooterCategory will be visible to.
*
* @param int[] $user_group_ids Identifiers of user groups that this TroubleshooterCategory will be visible to.
* @return kyTroubleshooterCategory
*/
public function setUserGroupIds($user_group_ids) {
//normalization to array
if (!is_array($user_group_ids)) {
if (is_numeric($user_group_ids)) {
$user_group_ids = array($user_group_ids);
} else {
$user_group_ids = array();
}
}
//normalization to positive integer values
$this->user_group_ids = array();
foreach ($user_group_ids as $user_group_id) {
$user_group_id = ky_assure_positive_int($user_group_id);
if ($user_group_id === null)
continue;
$this->user_group_ids[] = $user_group_id;
}
return $this;
}
/**
* Returns true to indicate that visibility of this TroubleshooterCategory is restricted to particular staff groups.
* Use getStaffGroupIds to get their identifiers or getStaffGroups to get the objects.
*
* @return bool
* @filterBy
*/
public function getStaffVisibilityCustom() {
return $this->staff_visibility_custom;
}
/**
* Sets whether to restrict visibility of this TroubleshooterCategory item to particular staff groups.
* Use setStaffGroupIds to set these groups using identifiers to set them using objects.
* Automatically clears staff groups when set to false.
*
* @param bool $staff_visibility_custom True to restrict visibility of this TroubleshooterCategory to particular staff groups. False otherwise.
* @return kyTroubleshooterCategory
*/
public function setStaffVisibilityCustom($staff_visibility_custom) {
$this->staff_visibility_custom = ky_assure_bool($staff_visibility_custom);
if ($this->staff_visibility_custom === false) {
$this->staff_group_ids = array();
$this->staff_groups = null;
}
return $this;
}
/**
* Returns identifiers of staff groups that this TroubleshooterCategory item will be visible to.
*
* @return array
* @filterBy name=StaffGroupId
*/
public function getStaffGroupIds() {
return $this->staff_group_ids;
}
/**
* Sets staff groups (using their identifiers) that this TroubleshooterCategory item will be visible to.
*
* @param int[] $staff_group_ids Identifiers of staff groups that this TroubleshooterCategory item will be visible to.
* @return kyTroubleshooterCategory
*/
public function setStaffGroupIds($staff_group_ids) {
//normalization to array
if (!is_array($staff_group_ids)) {
if (is_numeric($staff_group_ids)) {
$staff_group_ids = array($staff_group_ids);
} else {
$staff_group_ids = array();
}
}
//normalization to positive integer values
$this->staff_group_ids = array();
foreach ($staff_group_ids as $staff_group_id) {
$staff_group_id = ky_assure_positive_int($staff_group_id);
if ($staff_group_id === null)
continue;
$this->staff_group_ids[] = $staff_group_id;
}
return $this;
}
/**
* Returns staff Id of the TroubleshooterCategory.
*
* @return int
* @filterBy
* @orderBy
*/
public function getStaffId() {
return $this->staff_id;
}
/**
* Sets staff Id of the TroubleshooterCategory.
*
* @param string $staff_id of the knoledgebase category.
* @return kyTroubleshooterCategory
*/
public function setStaffId($staff_id) {
$this->staff_id = ky_assure_positive_int($staff_id);
return $this;
}
/**
* Creates a TroubleshooterCategory.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @see TroubleshooterCategory::CATEGORY_TYPE constants.
*
* @param string $title Title of TroubleshooterCategory.
* @param int $category_type Category type of troubleshooter item.
* @param kyStaff $staff Staff user.
* @return kyTroubleshooterCategory
*/
static public function createNew($title, $category_type, kyStaff $staff) {
$new_troubleshooter_category = new kyTroubleshooterCategory();
$new_troubleshooter_category->setTitle($title);
$new_troubleshooter_category->setCategoryType($category_type);
$new_troubleshooter_category->setStaff($staff);
return $new_troubleshooter_category;
}
}