-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathkyNewsComment.php
More file actions
140 lines (125 loc) · 3.21 KB
/
kyNewsComment.php
File metadata and controls
140 lines (125 loc) · 3.21 KB
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
<?php
/**
* Kayako NewsComment object.
*
* @author Tomasz Sawicki (https://github.com/Furgas)
* @link http://wiki.kayako.com/display/DEV/REST+-+NewsComment
* @since Kayako version 4.51.1891
* @package Object\News
*
* @noinspection PhpDocSignatureInspection
*/
class kyNewsComment extends kyCommentBase
{
protected static $controller = '/News/Comment';
protected static $object_xml_name = 'newsitemcomment';
/**
* News item identifier.
* @apiField required_create=true
* @var int
*/
protected $news_item_id;
/**
* News item.
* @var kyNewsItem
*/
protected $news_item;
protected function parseData($data)
{
parent::parseData($data);
$this->news_item_id = ky_assure_positive_int($data['newsitemid']);
}
public function buildData($create)
{
$data = parent::buildData($create);
$this->buildDataNumeric($data, 'newsitemid', $this->news_item_id);
return $data;
}
/**
* Returns all comment of news item.
*
* @param kyNewsItem $knowledgebase_article News item.
* @return kyResultSet
*/
public static function getAll()
{
list($knowledgebase_article) = func_get_args();
if ($knowledgebase_article instanceof kyNewsItem) {
$news_item_id = $knowledgebase_article->getId();
} else {
$news_item_id = $knowledgebase_article;
}
return parent::getAll(array('ListAll', $news_item_id));
}
/**
* Return news item identifier.
*
* @return int
* @filterBy
* @orderBy
*/
public function getNewsItemId()
{
return $this->news_item_id;
}
/**
* Sets news item identifier.
*
* @param int $news_item_id News item identifier.
* @return kyNewsComment
*/
public function setNewsItemId($news_item_id)
{
$this->news_item_id = ky_assure_positive_int($news_item_id);
$this->news_item = null;
return $this;
}
/**
* Return news item.
*
* 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 kyNewsItem
*/
public function getNewsItem($reload = false)
{
if ($this->news_item !== null && !$reload) {
return $this->news_item;
}
if ($this->news_item_id === null) {
return null;
}
$this->news_item = kyNewsItem::get($this->news_item_id);
return $this->news_item;
}
/**
* Sets news item.
*
* @param kyNewsItem $news_item News item.
* @return kyNewsComment
*/
public function setNewsItem($news_item)
{
$this->news_item = ky_assure_object($news_item, 'kyNewsItem');
$this->news_item_id = $this->news_item !== null ? $this->news_item->getId() : null;
return $this;
}
/**
* Creates a new news item comment.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @param kyNewsItem $knowledgebase_article News item.
* @param kyUser|kyStaff|string $creator Creator (staff object, user object or user fullname) of this comment.
* @param string $contents Contents of this comment.
* @return kyNewsComment
*/
public static function createNew()
{
list($knowledgebase_article, $creator, $contents) = func_get_args();
/** @var $new_comment kyNewsComment */
$new_comment = parent::createNew($creator, $contents);
$new_comment->setNewsItem($knowledgebase_article);
return $new_comment;
}
}