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
|
11 |
|
public function __construct($json = null) |
37
|
|
|
{ |
38
|
11 |
|
if ($json) { |
39
|
1 |
|
$this->parseJson($json); |
40
|
|
|
} else { |
41
|
10 |
|
$this->color = self::COLOR_YELLOW; |
42
|
10 |
|
$this->messageFormat = self::FORMAT_HTML; |
43
|
10 |
|
$this->message = ""; |
44
|
10 |
|
$this->notify = false; |
45
|
|
|
} |
46
|
11 |
|
} |
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
|
2 |
|
public function setColor($color) |
85
|
|
|
{ |
86
|
2 |
|
$this->color = $color; |
87
|
2 |
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @inheritdoc |
92
|
|
|
*/ |
93
|
1 |
|
public function getColor() |
94
|
|
|
{ |
95
|
1 |
|
return $this->color; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @inheritdoc |
100
|
|
|
*/ |
101
|
2 |
|
public function setMessage($message) |
102
|
|
|
{ |
103
|
2 |
|
$this->message = $message; |
104
|
2 |
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @inheritdoc |
109
|
|
|
*/ |
110
|
1 |
|
public function getMessage() |
111
|
|
|
{ |
112
|
1 |
|
return $this->message; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @inheritdoc |
117
|
|
|
*/ |
118
|
1 |
|
public function setNotify($notify) |
119
|
|
|
{ |
120
|
1 |
|
$this->notify = $notify; |
121
|
1 |
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @inheritdoc |
126
|
|
|
*/ |
127
|
1 |
|
public function isNotify() |
128
|
|
|
{ |
129
|
1 |
|
return $this->notify; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @inheritdoc |
134
|
|
|
*/ |
135
|
1 |
|
public function setMessageFormat($messageFormat) |
136
|
|
|
{ |
137
|
1 |
|
$this->messageFormat = $messageFormat; |
138
|
1 |
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @inheritdoc |
143
|
|
|
*/ |
144
|
1 |
|
public function getMessageFormat() |
145
|
|
|
{ |
146
|
1 |
|
return $this->messageFormat; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @inheritdoc |
151
|
|
|
*/ |
152
|
1 |
|
public function setFrom($from) |
153
|
|
|
{ |
154
|
1 |
|
$this->from = $from; |
155
|
1 |
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @inheritdoc |
160
|
|
|
*/ |
161
|
1 |
|
public function getFrom() |
162
|
|
|
{ |
163
|
1 |
|
return $this->from; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|