-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathkyKnowledgebaseCategory.php
591 lines (526 loc) · 15.8 KB
/
kyKnowledgebaseCategory.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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
<?php
/**
* Kayako KnowledgebaseCategory object.
*
*
* @author Saloni Dhall (https://github.com/SaloniDhall)
* @link http://wiki.kayako.com/display/DEV/REST+-+KnowledgebaseCategory
* @since Kayako version 4.64
* @package Object\Knowledgebase
*
* @noinspection PhpDocSignatureInspection
*/
class kyKnowledgebaseCategory extends kyObjectBase {
/**
* Knowledegbase category type - Global.
* Private knowledegbase categories are visible in your end users in the support center and in the staff control panel.
*
* @var int
*/
const CATEGORY_TYPE_GLOBAL = '1';
/**
* Knowledegbase category type - Public.
* Public knowledgebase categories are visible in both the support center.
*
* @var int
*/
const CATEGORY_TYPE_PUBLIC = '2';
/**
* Knowledegbase category type - Private.
* Private knowledegbase categories are visible only in Staff CP.
*
* @var int
*/
const CATEGORY_TYPE_PRIVATE = '3';
/**
* Knowledegbase category type - Inherit.
* The category will inherit the scope of its parent category.
*
* @var int
*/
const CATEGORY_TYPE_INHERIT = '4';
static protected $controller = '/Knowledgebase/Category';
static protected $object_xml_name = 'kbcategory';
/**
* Knowledegbase category identifier.
* @apiField
* @var int
*/
protected $id;
/**
* Knowledegbase category title.
* @apiField required=true
* @var string
*/
protected $title;
/**
* Knowledegbase category type.
* @apiField required=true
* @var int
*/
protected $category_type;
/**
* Knowledegbase parent category Id.
* @apiField required=optional
* @var int
*/
protected $parent_kbcategoryid;
/**
* Knowledegbase category display order
* @apiField required=optional
* @var int
*/
protected $displayorder;
/**
* Knowledegbase category article_sortorder.
* @apiField required=optional
* @var string
*/
protected $article_sortorder;
/**
* Knowledegbase category allow_comments.
* @apiField required=optional
* @var int
*/
protected $allow_comments;
/**
* Knowledegbase category allow_rating.
* @apiField required=optional
* @var int
*/
protected $allow_rating;
/**
* Knowledegbase category is_published.
* @apiField required=optional
* @var string(yes or no)
*/
protected $is_published;
/**
* If this Knowledegbase category is visible to specific user groups only
* @see kyKnowledgebaseCategory::$user_group_ids
* @var bool
*/
protected $user_visibility_custom;
/**
* User group identifiers this Knowledegbase category is visible to.
* @apiField name=usergroupidlist
* @var int[]
*/
protected $user_group_ids;
/**
* If this knowledgebase category is visible to specific staff groups only.
* @see kyKnowledgebaseCategory::$staff_group_ids
* @apiField
* @var bool
*/
protected $staff_visibility_custom;
/**
* User group identifiers this knowledgebase category is visible to.
* @apiField name=staffgroupidlist
* @var int[]
*/
protected $staff_group_ids = array();
/**
* Knowledegbase category created by which staff Id
* @apiField required=optional
* @var int
*/
protected $staff_id;
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->parent_kbcategoryid = ky_assure_positive_int($data['parentkbcategoryid']);
$this->displayorder = ky_assure_positive_int($data['displayorder']);
$this->allow_comments = ky_assure_bool($data['allowcomments']);
$this->allow_rating = ky_assure_bool($data['allowrating']);
$this->is_published = ky_assure_bool($data['ispublished']);
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) {
$this->checkRequiredAPIFields($create);
$data = array();
$this->buildDataString($data, 'title', $this->title);
$this->buildDataString($data, 'categorytype', $this->category_type);
$this->buildDataNumeric($data, 'parentkbategoryid', $this->parent_kbcategoryid);
$this->buildDataNumeric($data, 'displayorder', $this->displayorder);
$this->buildDataNumeric($data, 'articlesortorder', $this->article_sortorder);
$this->buildDataBool($data, 'allowcomments', $this->allow_comments);
$this->buildDataBool($data, 'allowrating', $this->allow_rating);
$this->buildDataString($data, 'ispublished', $this->is_published);
$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->buildDataString($data, 'staffid', $this->staff_id);
return $data;
}
/**
* Returns all categories of knowledgebase.
*
* @param int $starting_kbcategory_id Optional starting kbcategoryid identifier.
* @param int $max_items Optional maximum items count. Defaults to 1000 when starting kbcategoryid is defined.
* @return kyResultSet
*/
static public function getAll($max_items = null, $starting_kbcategory_id = 0) {
$search_parameters = array('GetList');
if (is_numeric($starting_kbcategory_id) && $starting_kbcategory_id > 0) {
if (!is_numeric($max_items) || $max_items <= 0) {
$max_items = 1000;
}
$search_parameters[] = $max_items;
$search_parameters[] = $starting_kbcategory_id;
}
return parent::getAll($search_parameters);
}
public function toString() {
return sprintf("%s (category type: %s)", $this->getTitle(), $this->getCategoryType());
}
public function getId($complete = false) {
return $complete ? array($this->id) : $this->id;
}
/**
* Return category type of the knowledgebase category.
*
* @see kyKnowledgebaseCategory::CATEGORY_TYPE constants.
*
* @return int
* @filterBy
* @orderBy
*/
public function getCategoryType() {
return $this->category_type;
}
/**
* Sets category type of the knowledgebase category.
*
* @see kyKnowledgebaseCategory::CATEGORY_TYPE constants.
*
* @param int $category_type Category type of the knowledgebase category.
* @return kyKnowledgebaseCategory
*/
public function setCategoryType($category_type) {
$this->category_type = ky_assure_constant($category_type, $this, 'CATEGORY_TYPE');
return $this;
}
/**
* Returns title of the knowledgebase category.
*
* @return string
* @filterBy
* @orderBy
*/
public function getTitle() {
return $this->title;
}
/**
* Sets title of the knowledgebase category.
*
* @param string $title Title of the knowledgebase category.
* @return kyKnowledgebaseCategory
*/
public function setTitle($title) {
$this->title = ky_assure_string($title);
return $this;
}
/**
* Returns displayorder of the knowledgebase category.
*
* @return int
* @filterBy
* @orderBy
*/
public function getDisplayOrder() {
return $this->displayorder;
}
/**
* Sets displayorder of the knowledgebase category.
*
* @param int $display_order of the knowledgebase category.
* @return kyKnowledgebaseCategory
*/
public function setDisplayOrder($display_order) {
$this->displayorder = ky_assure_int($display_order, 0);
return $this;
}
/**
* Returns parentCategoryId of the knowledgebase category.
*
* @return string
* @filterBy
* @orderBy
*/
public function getParentCategoryId() {
return $this->parent_kbcategoryid;
}
/**
* Sets parentCategoryId of the knowledgebase category.
*
* @param int $parent_categoryid of the knowledgebase category.
* @return kyKnowledgebaseCategory
*/
public function setParentCategoryId($parent_categoryid) {
$this->parent_kbcategoryid = ky_assure_int($parent_categoryid);
return $this;
}
/**
* Returns articlesortorder of the knowledgebase category.
*
* @return int
* @filterBy
* @orderBy
*/
public function getArticleSortOrder() {
return $this->article_sortorder;
}
/**
* Sets articlesortorder of the knowledgebase category.
*
* @param int $articlesortorder Sort Order of the knowledgebase category.
* @return kyKnowledgebaseCategory
*/
public function setArticleSortOrder($articlesortorder) {
$this->article_sortorder = ky_assure_int($articlesortorder);
return $this;
}
/**
* Returns allow_comments of the knowledgebase category.
*
* @return bool
* @filterBy
* @orderBy
*/
public function getAllowComments() {
return $this->allow_comments;
}
/**
* Sets allow_comments of the knowledgebase category.
*
* @param string $allow_comments Title of the knowledgebase category.
* @return kyKnowledgebaseCategory
*/
public function setAllowComments($allow_comments) {
$this->allow_comments = ky_assure_bool($allow_comments);
return $this;
}
/**
* Returns allow_rating of the knowledgebase category.
*
* @return bool
* @filterBy
* @orderBy
*/
public function getAllowRating() {
return $this->allow_rating;
}
/**
* Sets allow_rating of the knowledgebase category.
*
* @param bool $allow_rating knowledgebase category.
* @return kyKnowledgebaseCategory
*/
public function setAllowRating($allow_rating) {
$this->allow_rating = ky_assure_bool($allow_rating);
return $this;
}
/**
* Returns is_published of the knowledgebase category.
*
* @return bool
* @filterBy
* @orderBy
*/
public function getIsPublished() {
return $this->is_published;
}
/**
* Sets is_published of the knowledgebase category.
*
* @param bool $is_published knowledgebase category.
* @return kyKnowledgebaseCategory
*/
public function setIsPublished($is_published) {
$this->is_published = ky_assure_bool($is_published);
return $this;
}
/**
* Returns true to indicate that visibility of this knowledgebase category 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 knowledgebase category 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 knowledgebase category to particular user groups. False otherwise.
* @return kyKnowledgebaseCategory
*/
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 knowledgebase category 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 knowledgebase category will be visible to.
*
* @param int[] $user_group_ids Identifiers of user groups that this knowledgebase category will be visible to.
* @return kyKnowledgebaseCategory
*/
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 knowledgebase category 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 knowledgebase category 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 knowledgebase category to particular staff groups. False otherwise.
* @return kyKnowledgebaseCategory
*/
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 knowledgebase category 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 knowledgebase category item will be visible to.
*
* @param int[] $staff_group_ids Identifiers of staff groups that this knowledgebase category item will be visible to.
* @return kyKnowledgebaseCategory
*/
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 knowledgebase category.
*
* @return int
* @filterBy
* @orderBy
*/
public function getStaffId() {
return $this->staff_id;
}
/**
* Sets staff Id of the knowledgebase category.
*
* @param string $staff_id of the knoledgebase category.
* @return kyKnowledgebaseCategory
*/
public function setStaffId($staff_id) {
$this->staff_id = ky_assure_positive_int($staff_id);
return $this;
}
/**
* Creates a knowledegbase category.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @see kyKnowledgebaseCategory::CATEGORY_TYPE constants.
*
* @param string $title Title of knowledgebase category.
* @param int $category_type Category type of knowledgebase item.
* @return kyKnowledgebaseCategory
*/
static public function createNew($title, $category_type) {
$new_knowledgebase_category = new kyKnowledgebaseCategory();
$new_knowledgebase_category->setTitle($title);
$new_knowledgebase_category->setCategoryType($category_type);
return $new_knowledgebase_category;
}
}