1 | <?php |
||
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) |
||
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() |
||
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) |
||
92 | |||
93 | /** |
||
94 | * Returns background color for message |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | public function getColor() |
||
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) |
||
115 | |||
116 | /** |
||
117 | * Returns the message body |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | public function getMessage() |
||
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) |
||
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() |
||
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) |
||
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() |
||
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) |
||
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() |
||
195 | } |
||
196 |