-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathkyNewsCategory.php
164 lines (144 loc) · 3.78 KB
/
kyNewsCategory.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
<?php
/**
* Kayako NewsCategory object.
* Known issues:
* - news items count not updated after removing news item (http://dev.kayako.com/browse/SWIFT-3112)
*
* @author Tomasz Sawicki (https://github.com/Furgas)
* @link http://wiki.kayako.com/display/DEV/REST+-+NewsCategory
* @since Kayako version 4.51.1891
* @package Object\News
*
* @noinspection PhpDocSignatureInspection
*/
class kyNewsCategory extends kyObjectBase {
/**
* News category visibility type - Public.
* Public news categories are visible in both the support center and Staff CP.
*
* @var string
*/
const VISIBILITY_TYPE_PUBLIC = 'public';
/**
* News category visibility type - Private.
* Private news categories are visible only in Staff CP.
*
* @var string
*/
const VISIBILITY_TYPE_PRIVATE = 'private';
static protected $controller = '/News/Category';
static protected $object_xml_name = 'newscategory';
/**
* News category identifier.
* @apiField
* @var int
*/
protected $id;
/**
* News category title.
* @apiField required=true
* @var string
*/
protected $title;
/**
* Total count of news items in this category.
* @apiField
* @var int
*/
protected $news_item_count = 0;
/**
* News category visibility type.
* @apiField required=true
* @var int
*/
protected $visibility_type;
protected function parseData($data) {
$this->id = ky_assure_positive_int($data['id']);
$this->title = ky_assure_string($data['title']);
$this->visibility_type = ky_assure_string($data['visibilitytype']);
$this->news_item_count = ky_assure_positive_int($data['newsitemcount'], 0);
}
public function buildData($create) {
$this->checkRequiredAPIFields($create);
$data = array();
$this->buildDataString($data, 'title', $this->title);
$this->buildDataString($data, 'visibilitytype', $this->visibility_type);
return $data;
}
public function toString() {
return sprintf("%s (visbility type: %s)", $this->getTitle(), $this->getVisibilityType());
}
public function getId($complete = false) {
return $complete ? array($this->id) : $this->id;
}
/**
* Return visibility type of the news category.
*
* @see kyNewsCategory::VISIBILITY_TYPE constants.
*
* @return int
* @filterBy
* @orderBy
*/
public function getVisibilityType() {
return $this->visibility_type;
}
/**
* Sets visibility type of the news category.
*
* @see kyNewsCategory::VISIBILITY_TYPE constants.
*
* @param int $visibility_type Visibility type of the news category.
* @return kyNewsCategory
*/
public function setVisibilityType($visibility_type) {
$this->visibility_type = ky_assure_constant($visibility_type, $this, 'VISIBILITY_TYPE');
return $this;
}
/**
* Returns title of the news category.
*
* @return string
* @filterBy
* @orderBy
*/
public function getTitle() {
return $this->title;
}
/**
* Sets title of the news category.
*
* @param string $title Title of the news category.
* @return kyNewsCategory
*/
public function setTitle($title) {
$this->title = ky_assure_string($title);
return $this;
}
/**
* Returns total count of news items in this category.
*
* @return int
* @filterBy
* @orderBy
*/
public function getNewsItemCount() {
return $this->news_item_count;
}
/**
* Creates a news category.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @see kyNewsCategory::VISIBILITY_TYPE constants.
*
* @param string $title Title of news category.
* @param int $visibility_type Visibility type of news item.
* @return kyNewsCategory
*/
static public function createNew($title, $visibility_type) {
$new_news_category = new kyNewsCategory();
$new_news_category->setTitle($title);
$new_news_category->setVisibilityType($visibility_type);
return $new_news_category;
}
}