1 | <?php namespace Cornford\Notifier\Models; |
||
8 | class Notification implements NotifierNotificationInterface { |
||
9 | |||
10 | const NOTIFICATION_TYPE_NONE = 'message'; |
||
11 | const NOTIFICATION_TYPE_INFO = 'info'; |
||
12 | const NOTIFICATION_TYPE_SUCCESS = 'success'; |
||
13 | const NOTIFICATION_TYPE_WARNING = 'warn'; |
||
14 | const NOTIFICATION_TYPE_DANGER = 'error'; |
||
15 | |||
16 | /** |
||
17 | * Options. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $options = []; |
||
22 | |||
23 | /** |
||
24 | * Notification id. |
||
25 | * |
||
26 | * @var integer |
||
27 | */ |
||
28 | protected $id; |
||
29 | |||
30 | /** |
||
31 | * Notification message. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $message; |
||
36 | |||
37 | /** |
||
38 | * Notification message type. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $type; |
||
43 | |||
44 | /** |
||
45 | * Notification message date time. |
||
46 | * |
||
47 | * @var DateTime |
||
48 | */ |
||
49 | protected $datetime; |
||
50 | |||
51 | /** |
||
52 | * Notification message expiry in minutes. |
||
53 | * |
||
54 | * @var DateTime|integer |
||
55 | */ |
||
56 | protected $expiry; |
||
57 | |||
58 | /** |
||
59 | * Notification message displayed status. |
||
60 | * |
||
61 | * @var boolean |
||
62 | */ |
||
63 | protected $displayed = false; |
||
64 | |||
65 | /** |
||
66 | * Constructor. |
||
67 | * |
||
68 | * @param integer $id |
||
69 | * @param string $message |
||
70 | * @param string $type |
||
71 | * @param DateTime $datetime |
||
72 | * @param DateTime|integer $expiry |
||
73 | * @param array $options |
||
74 | * |
||
75 | * @throws NotifierNotificationArgumentException |
||
76 | */ |
||
77 | public function __construct($id, $message, $type, $datetime, $expiry = 0, array $options = []) |
||
117 | |||
118 | /** |
||
119 | * Set the notification id. |
||
120 | * |
||
121 | * @param integer $value |
||
122 | * |
||
123 | * @return void |
||
124 | */ |
||
125 | public function setId($value) |
||
129 | |||
130 | /** |
||
131 | * Get the notification id. |
||
132 | * |
||
133 | * @return integer |
||
134 | */ |
||
135 | public function getId() |
||
139 | |||
140 | /** |
||
141 | * Set the notification message. |
||
142 | * |
||
143 | * @param string $value |
||
144 | * |
||
145 | * @return void |
||
146 | */ |
||
147 | public function setMessage($value) |
||
151 | |||
152 | /** |
||
153 | * Get the notification message. |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | public function getMessage() |
||
161 | |||
162 | /** |
||
163 | * Set the notification message type. |
||
164 | * |
||
165 | * @param string $value |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | public function setType($value) |
||
173 | |||
174 | /** |
||
175 | * Get the notification message. |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | public function getType() |
||
183 | |||
184 | /** |
||
185 | * Set the notification message date time. |
||
186 | * |
||
187 | * @param DateTime $value |
||
188 | * |
||
189 | * @return void |
||
190 | */ |
||
191 | public function setDatetime($value) |
||
195 | |||
196 | /** |
||
197 | * Get the notification message date time. |
||
198 | * |
||
199 | * @return DateTime |
||
200 | */ |
||
201 | public function getDatetime() |
||
205 | |||
206 | /** |
||
207 | * Set the notification message expiry in minutes or with a DateTime object. |
||
208 | * |
||
209 | * @param DateTime|integer $value |
||
210 | * |
||
211 | * @return void |
||
212 | */ |
||
213 | public function setExpiry($value) |
||
217 | |||
218 | /** |
||
219 | * Get the notification message expiry in minutes or a DateTime object. |
||
220 | * |
||
221 | * @return DateTime|integer |
||
222 | */ |
||
223 | public function getExpiry() |
||
227 | |||
228 | /** |
||
229 | * Calculate the number of minutes between now and the given duration. |
||
230 | * |
||
231 | * @param DateTime|integer $duration |
||
232 | * |
||
233 | * @return integer |
||
234 | */ |
||
235 | protected function getMinutes($duration) |
||
251 | |||
252 | /** |
||
253 | * Is notification message expired. |
||
254 | * |
||
255 | * @return boolean |
||
256 | */ |
||
257 | public function isExpired() |
||
267 | |||
268 | /** |
||
269 | * Set the notification message displayed status. |
||
270 | * |
||
271 | * @param boolean $value |
||
272 | * |
||
273 | * @return void |
||
274 | */ |
||
275 | public function setDisplayed($value) |
||
279 | |||
280 | /** |
||
281 | * Get the notification message displayed status. |
||
282 | * |
||
283 | * @return boolean |
||
284 | */ |
||
285 | public function getDisplayed() |
||
289 | |||
290 | /** |
||
291 | * Get the notification message displayed status. |
||
292 | * |
||
293 | * @return boolean |
||
294 | */ |
||
295 | public function isDisplayed() |
||
299 | |||
300 | /** |
||
301 | * Set the notification message options. |
||
302 | * |
||
303 | * @param array $value |
||
304 | * |
||
305 | * @return void |
||
306 | */ |
||
307 | public function setOptions(array $value) |
||
311 | |||
312 | /** |
||
313 | * Get the notification message options. |
||
314 | * |
||
315 | * @return array |
||
316 | */ |
||
317 | public function getOptions() |
||
321 | |||
322 | /** |
||
323 | * To array method. |
||
324 | * |
||
325 | * @return array |
||
326 | */ |
||
327 | public function __toArray() |
||
340 | |||
341 | } |