Completed
Pull Request — master (#35)
by
unknown
05:36
created

Message::getDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 date of message.
95
     *
96
     * @return String
97
     */
98
    public function getDate()
99
    {
100
        return $this->date;
101
    }
102
103
    public function getID()
104
    {
105
        return $this->id;
106
    }
107
108
    /**
109
     * Returns background color for message
110
     *
111
     * @return string
112
     */
113
    public function getColor()
114
    {
115
        return $this->color;
116
    }
117
118
    /**
119
     * Sets the message body
120
     *
121
     * @param string $message The message body
122
     *
123
     * @return self
124
     */
125
    public function setMessage($message)
126
    {
127
        $this->message = $message;
128
        return $this;
129
    }
130
131
    /**
132
     * Returns the message body
133
     *
134
     * @return string
135
     */
136
    public function getMessage()
137
    {
138
        return $this->message;
139
    }
140
141
    /**
142
     * Sets whether or not this message should trigger a notification
143
     *
144
     * @param boolean $notify Whether or not this message should trigger a notification
145
     *
146
     * @return self
147
     */
148
    public function setNotify($notify)
149
    {
150
        $this->notify = $notify;
151
        return $this;
152
    }
153
154
    /**
155
     * Returns whether or not this message should trigger a notification for people in the room
156
     * (change the tab color, play a sound, etc). Each recipient's notification preferences are taken into account.
157
     *
158
     * @return boolean
159
     */
160
    public function isNotify()
161
    {
162
        return $this->notify;
163
    }
164
165
    /**
166
     * Sets how the message is treated by the server and rendered inside HipChat applications
167
     *
168
     * @param string $messageFormat How the message is treated by the server and rendered inside HipChat applications
169
     *
170
     * @return self
171
     */
172
    public function setMessageFormat($messageFormat)
173
    {
174
        $this->messageFormat = $messageFormat;
175
        return $this;
176
    }
177
178
    /**
179
     * Returns how the message is treated by the server and rendered inside HipChat applications
180
     *
181
     * @return string
182
     */
183
    public function getMessageFormat()
184
    {
185
        return $this->messageFormat;
186
    }
187
188
    /**
189
     * Sets a label to be shown in addition to the sender's name
190
     *
191
     * @param string $from The label
192
     *
193
     * @return self
194
     */
195
    public function setFrom($from)
196
    {
197
        $this->from = $from;
198
        return $this;
199
    }
200
201
    /**
202
     * Gets the label to be shown in addition to the sender's name
203
     *
204
     * @return string|array
205
     */
206
    public function getFrom()
207
    {
208
        return $this->from;
209
    }
210
}
211