1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SolutionDrive\HipchatAPIv2Client\Model; |
4
|
|
|
|
5
|
|
|
class Message implements MessageInterface |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
protected $id = null; |
9
|
|
|
|
10
|
|
|
protected $color; |
11
|
|
|
|
12
|
|
|
protected $message; |
13
|
|
|
|
14
|
|
|
protected $notify; |
15
|
|
|
|
16
|
|
|
protected $messageFormat; |
17
|
|
|
|
18
|
|
|
protected $date = null; |
19
|
|
|
|
20
|
|
|
protected $from = ''; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
const COLOR_YELLOW = 'yellow'; |
24
|
|
|
const COLOR_GREEN = 'green'; |
25
|
|
|
const COLOR_RED = 'red'; |
26
|
|
|
const COLOR_PURPLE = 'purple'; |
27
|
|
|
const COLOR_GRAY = 'gray'; |
28
|
|
|
const COLOR_RANDOM = 'random'; |
29
|
|
|
|
30
|
|
|
const FORMAT_HTML = 'html'; |
31
|
|
|
const FORMAT_TEXT = 'text'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Message constructor |
35
|
|
|
*/ |
36
|
13 |
|
public function __construct($json = null) |
37
|
|
|
{ |
38
|
13 |
|
if ($json) { |
39
|
1 |
|
$this->parseJson($json); |
40
|
|
|
} else { |
41
|
12 |
|
$this->color = self::COLOR_YELLOW; |
42
|
12 |
|
$this->messageFormat = self::FORMAT_HTML; |
43
|
12 |
|
$this->message = ""; |
44
|
12 |
|
$this->notify = false; |
45
|
|
|
} |
46
|
13 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritdoc |
50
|
|
|
*/ |
51
|
2 |
|
public function parseJson($json) |
52
|
|
|
{ |
53
|
2 |
|
$this->id = $json['id']; |
54
|
2 |
|
$this->from = is_array($json['from']) ? $json['from']['name'] : $json['from']; |
55
|
2 |
|
$this->message = $json['message']; |
56
|
2 |
|
$this->color = isset($json['color']) ? $json['color'] : null; |
57
|
2 |
|
$this->notify = $json['notify']; |
58
|
2 |
|
$this->messageFormat = isset($json['message_format']) ? $json['message_format'] : 'html'; |
59
|
2 |
|
$this->date = $json['date']; |
60
|
2 |
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritdoc |
65
|
|
|
*/ |
66
|
1 |
|
public function toJson() |
67
|
|
|
{ |
68
|
1 |
|
$json = array(); |
69
|
1 |
|
$json['id'] = $this->id; |
70
|
1 |
|
$json['from'] = $this->from; |
71
|
1 |
|
$json['color'] = $this->color; |
72
|
1 |
|
$json['message'] = $this->message; |
73
|
1 |
|
$json['notify'] = $this->notify; |
74
|
1 |
|
$json['message_format'] = $this->messageFormat; |
75
|
1 |
|
$json['date'] = $this->date; |
76
|
|
|
|
77
|
1 |
|
return $json; |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritdoc |
83
|
|
|
*/ |
84
|
1 |
|
public function setId($id) |
85
|
|
|
{ |
86
|
1 |
|
$this->id = $id; |
87
|
|
|
|
88
|
1 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritdoc |
93
|
|
|
*/ |
94
|
1 |
|
public function getId() |
95
|
|
|
{ |
96
|
1 |
|
return $this->id; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @inheritdoc |
101
|
|
|
*/ |
102
|
2 |
|
public function setColor($color) |
103
|
|
|
{ |
104
|
2 |
|
$this->color = $color; |
105
|
2 |
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @inheritdoc |
110
|
|
|
*/ |
111
|
1 |
|
public function getColor() |
112
|
|
|
{ |
113
|
1 |
|
return $this->color; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @inheritdoc |
118
|
|
|
*/ |
119
|
2 |
|
public function setMessage($message) |
120
|
|
|
{ |
121
|
2 |
|
$this->message = $message; |
122
|
2 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @inheritdoc |
127
|
|
|
*/ |
128
|
1 |
|
public function getMessage() |
129
|
|
|
{ |
130
|
1 |
|
return $this->message; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @inheritdoc |
135
|
|
|
*/ |
136
|
1 |
|
public function setNotify($notify) |
137
|
|
|
{ |
138
|
1 |
|
$this->notify = $notify; |
139
|
1 |
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @inheritdoc |
144
|
|
|
*/ |
145
|
1 |
|
public function isNotify() |
146
|
|
|
{ |
147
|
1 |
|
return $this->notify; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @inheritdoc |
152
|
|
|
*/ |
153
|
1 |
|
public function setMessageFormat($messageFormat) |
154
|
|
|
{ |
155
|
1 |
|
$this->messageFormat = $messageFormat; |
156
|
1 |
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @inheritdoc |
161
|
|
|
*/ |
162
|
1 |
|
public function getMessageFormat() |
163
|
|
|
{ |
164
|
1 |
|
return $this->messageFormat; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @inheritdoc |
169
|
|
|
*/ |
170
|
|
|
public function setDate($date) |
171
|
|
|
{ |
172
|
|
|
$this->date = $date; |
173
|
|
|
|
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @inheritdoc |
179
|
|
|
*/ |
180
|
|
|
public function getDate() |
181
|
|
|
{ |
182
|
|
|
return $this->date; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @inheritdoc |
187
|
|
|
*/ |
188
|
2 |
|
public function setFrom($from) |
189
|
|
|
{ |
190
|
2 |
|
$this->from = $from; |
191
|
2 |
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @inheritdoc |
196
|
|
|
*/ |
197
|
2 |
|
public function getFrom() |
198
|
|
|
{ |
199
|
2 |
|
return $this->from; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|