|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GorkaLaucirica\HipchatAPIv2Client\Model; |
|
4
|
|
|
|
|
5
|
|
|
class Message |
|
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
|
|
|
public function __construct($json = null) |
|
37
|
|
|
{ |
|
38
|
|
|
if ($json) { |
|
39
|
|
|
$this->parseJson($json); |
|
40
|
|
|
} else { |
|
41
|
|
|
$this->color = self::COLOR_YELLOW; |
|
42
|
|
|
$this->messageFormat = self::FORMAT_HTML; |
|
43
|
|
|
$this->message = ""; |
|
44
|
|
|
$this->notify = false; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function parseJson($json) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->id = $json['id']; |
|
51
|
|
|
$this->from = is_array($json['from']) ? $json['from']['name'] : $json['from']; |
|
52
|
|
|
$this->message = $json['message']; |
|
53
|
|
|
$this->color = isset($json['color']) ? $json['color'] : null; |
|
54
|
|
|
$this->notify = $json['notify']; |
|
55
|
|
|
$this->messageFormat = isset($json['message_format']) ? $json['message_format'] : 'html'; |
|
56
|
|
|
$this->date = $json['date']; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Serializes Message object |
|
62
|
|
|
* |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
|
|
public function toJson() |
|
66
|
|
|
{ |
|
67
|
|
|
$json = array(); |
|
68
|
|
|
$json['id'] = $this->id; |
|
69
|
|
|
$json['from'] = $this->from; |
|
70
|
|
|
$json['color'] = $this->color; |
|
71
|
|
|
$json['message'] = $this->message; |
|
72
|
|
|
$json['notify'] = $this->notify; |
|
73
|
|
|
$json['message_format'] = $this->messageFormat; |
|
74
|
|
|
$json['date'] = $this->date; |
|
75
|
|
|
|
|
76
|
|
|
return $json; |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Sets background color for message |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $color Background color for message |
|
84
|
|
|
* |
|
85
|
|
|
* @return self |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setColor($color) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->color = $color; |
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Returns background color for message |
|
95
|
|
|
* |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getColor() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->color; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Sets the message body |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $message The message body |
|
107
|
|
|
* |
|
108
|
|
|
* @return self |
|
109
|
|
|
*/ |
|
110
|
|
|
public function setMessage($message) |
|
111
|
|
|
{ |
|
112
|
|
|
$this->message = $message; |
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Returns the message body |
|
118
|
|
|
* |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getMessage() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->message; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Sets whether or not this message should trigger a notification |
|
128
|
|
|
* |
|
129
|
|
|
* @param boolean $notify Whether or not this message should trigger a notification |
|
130
|
|
|
* |
|
131
|
|
|
* @return self |
|
132
|
|
|
*/ |
|
133
|
|
|
public function setNotify($notify) |
|
134
|
|
|
{ |
|
135
|
|
|
$this->notify = $notify; |
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Returns whether or not this message should trigger a notification for people in the room |
|
141
|
|
|
* (change the tab color, play a sound, etc). Each recipient's notification preferences are taken into account. |
|
142
|
|
|
* |
|
143
|
|
|
* @return boolean |
|
144
|
|
|
*/ |
|
145
|
|
|
public function isNotify() |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->notify; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Sets how the message is treated by the server and rendered inside HipChat applications |
|
152
|
|
|
* |
|
153
|
|
|
* @param string $messageFormat How the message is treated by the server and rendered inside HipChat applications |
|
154
|
|
|
* |
|
155
|
|
|
* @return self |
|
156
|
|
|
*/ |
|
157
|
|
|
public function setMessageFormat($messageFormat) |
|
158
|
|
|
{ |
|
159
|
|
|
$this->messageFormat = $messageFormat; |
|
160
|
|
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Returns how the message is treated by the server and rendered inside HipChat applications |
|
165
|
|
|
* |
|
166
|
|
|
* @return string |
|
167
|
|
|
*/ |
|
168
|
|
|
public function getMessageFormat() |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->messageFormat; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Sets a label to be shown in addition to the sender's name |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $from The label |
|
177
|
|
|
* |
|
178
|
|
|
* @return self |
|
179
|
|
|
*/ |
|
180
|
|
|
public function setFrom($from) |
|
181
|
|
|
{ |
|
182
|
|
|
$this->from = $from; |
|
183
|
|
|
return $this; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Gets the label to be shown in addition to the sender's name |
|
188
|
|
|
* |
|
189
|
|
|
* @return string|array |
|
190
|
|
|
*/ |
|
191
|
|
|
public function getFrom() |
|
192
|
|
|
{ |
|
193
|
|
|
return $this->from; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|