-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathkyKnowledgebaseComment.php
More file actions
140 lines (125 loc) · 3.39 KB
/
kyKnowledgebaseComment.php
File metadata and controls
140 lines (125 loc) · 3.39 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 Knowledgebase comment object.
*
* @author Saloni Dhall (https://github.com/Furgas)
* @link http://wiki.kayako.com/display/DEV/REST+-+KnowledgebaseComment
* @since Kayako version 4.51.1891
* @package Object\Knowledgebase
*
*
*/
class kyKnowledgebaseComment extends kyCommentBase
{
protected static $controller = '/Knowledgebase/Comment';
protected static $object_xml_name = 'kbarticlecomment';
/**
* kbarticle identifier.
* @apiField required_create=true
* @var int
*/
protected $kbarticle_id;
/**
* kbarticle item.
* @var kyKnowledgebaseArticle
*/
protected $kbarticle;
protected function parseData($data)
{
parent::parseData($data);
$this->kbarticle_id = ky_assure_positive_int($data['kbarticleid']);
}
public function buildData($create)
{
$data = parent::buildData($create);
$this->buildDataNumeric($data, 'knowledgebasearticleid', $this->kbarticle_id);
return $data;
}
/**
* Returns all comment of kbarticle.
*
* @param kyKnowledgebaseArticle $kbarticle kyKnowledgebaseArticle item.
* @return kyResultSet
*/
public static function getAll()
{
list($kbarticle) = func_get_args();
if ($kbarticle instanceof kyKnowledgebaseArticle) {
$kbarticle_id = $kbarticle->getId();
} else {
$kbarticle_id = $kbarticle;
}
return parent::getAll(array('ListAll', $kbarticle_id));
}
/**
* Return KnowledgebaseArticle identifier.
*
* @return int
* @filterBy
* @orderBy
*/
public function getKbarticleId()
{
return $this->kbarticle_id;
}
/**
* Sets KnowledgebaseArticle identifier.
*
* @param int $kbarticle_id KnowledgebaseArticle identifier.
* @return kyKnowledgebaseArticle
*/
public function setKbarticleId($kbarticle_id)
{
$this->kbarticle_id = ky_assure_positive_int($kbarticle_id);
$this->kbarticle = null;
return $this;
}
/**
* Return KnowledgebaseArticle.
*
* 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 kyKnowledgebaseArticle
*/
public function getKbarticle($reload = false)
{
if ($this->kbarticle !== null && !$reload) {
return $this->kbarticle;
}
if ($this->kbarticle_id === null) {
return null;
}
$this->kbarticle = kyKnowledgebaseArticle::get($this->kbarticle_id);
return $this->kbarticle;
}
/**
* Sets KnowledgebaseArticle.
*
* @param kyKnowledgebaseArticle $kbarticle kbarticle item.
* @return kyKnowledgebaseComment
*/
public function setKbarticle($kbarticle)
{
$this->kbarticle = ky_assure_object($kbarticle, 'kyKnowledgebaseArticle');
$this->kbarticle_id = $this->kbarticle !== null ? $this->kbarticle->getId() : null;
return $this;
}
/**
* Creates a new Knowledgebase article comment.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @param kyKnowledgebaseArticle $kb_article KnowledgebaseArticle 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 kyKnowledgebaseComment
*/
public static function createNew()
{
list($kb_article, $creator, $contents) = func_get_args();
/** @var $kbarticle_comment kyKnowledgebaseComment */
$new_comment = parent::createNew($creator, $contents);
$new_comment->setKbarticle($kb_article);
return $new_comment;
}
}