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 message. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $message; |
||
29 | |||
30 | /** |
||
31 | * Notification message type. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $type; |
||
36 | |||
37 | /** |
||
38 | * Notification message date time. |
||
39 | * |
||
40 | * @var DateTime |
||
41 | */ |
||
42 | protected $datetime; |
||
43 | |||
44 | /** |
||
45 | * Notification message expiry in minutes. |
||
46 | * |
||
47 | * @var DateTime|integer |
||
48 | */ |
||
49 | protected $expiry; |
||
50 | |||
51 | /** |
||
52 | * Notification message displayed status. |
||
53 | * |
||
54 | * @var boolean |
||
55 | */ |
||
56 | protected $displayed = false; |
||
57 | |||
58 | /** |
||
59 | * Constructor. |
||
60 | * |
||
61 | * @param integer $id |
||
62 | * @param string $message |
||
63 | * @param string $type |
||
64 | * @param DateTime $datetime |
||
65 | * @param DateTime|integer $expiry |
||
66 | * @param array $options |
||
67 | * |
||
68 | * @throws NotifierNotificationArgumentException |
||
69 | */ |
||
70 | public function __construct($id, $message, $type, $datetime, $expiry = 0, array $options = []) |
||
110 | |||
111 | /** |
||
112 | * Set the notification id. |
||
113 | * |
||
114 | * @param integer $value |
||
115 | * |
||
116 | * @return void |
||
117 | */ |
||
118 | public function setId($value) |
||
122 | |||
123 | /** |
||
124 | * Get the notification id. |
||
125 | * |
||
126 | * @return integer |
||
127 | */ |
||
128 | public function getId() |
||
132 | |||
133 | /** |
||
134 | * Set the notification message. |
||
135 | * |
||
136 | * @param string $value |
||
137 | * |
||
138 | * @return void |
||
139 | */ |
||
140 | public function setMessage($value) |
||
144 | |||
145 | /** |
||
146 | * Get the notification message. |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | public function getMessage() |
||
154 | |||
155 | /** |
||
156 | * Set the notification message type. |
||
157 | * |
||
158 | * @param string $value |
||
159 | * |
||
160 | * @return void |
||
161 | */ |
||
162 | public function setType($value) |
||
166 | |||
167 | /** |
||
168 | * Get the notification message. |
||
169 | * |
||
170 | * @return string |
||
171 | */ |
||
172 | public function getType() |
||
176 | |||
177 | /** |
||
178 | * Set the notification message date time. |
||
179 | * |
||
180 | * @param DateTime $value |
||
181 | * |
||
182 | * @return void |
||
183 | */ |
||
184 | public function setDatetime($value) |
||
188 | |||
189 | /** |
||
190 | * Get the notification message date time. |
||
191 | * |
||
192 | * @return DateTime |
||
193 | */ |
||
194 | public function getDatetime() |
||
198 | |||
199 | /** |
||
200 | * Set the notification message expiry in minutes or with a DateTime object. |
||
201 | * |
||
202 | * @param DateTime|integer $value |
||
203 | * |
||
204 | * @return void |
||
205 | */ |
||
206 | public function setExpiry($value) |
||
210 | |||
211 | /** |
||
212 | * Get the notification message expiry in minutes or a DateTime object. |
||
213 | * |
||
214 | * @return DateTime|integer |
||
215 | */ |
||
216 | public function getExpiry() |
||
220 | |||
221 | /** |
||
222 | * Calculate the number of minutes between now and the given duration. |
||
223 | * |
||
224 | * @param DateTime|integer $duration |
||
225 | * |
||
226 | * @return integer |
||
227 | */ |
||
228 | protected function getMinutes($duration) |
||
244 | |||
245 | /** |
||
246 | * Is notification message expired. |
||
247 | * |
||
248 | * @return boolean |
||
249 | */ |
||
250 | public function isExpired() |
||
260 | |||
261 | /** |
||
262 | * Set the notification message displayed status. |
||
263 | * |
||
264 | * @param boolean $value |
||
265 | * |
||
266 | * @return void |
||
267 | */ |
||
268 | public function setDisplayed($value) |
||
272 | |||
273 | /** |
||
274 | * Get the notification message displayed status. |
||
275 | * |
||
276 | * @return boolean |
||
277 | */ |
||
278 | public function getDisplayed() |
||
282 | |||
283 | /** |
||
284 | * Get the notification message displayed status. |
||
285 | * |
||
286 | * @return boolean |
||
287 | */ |
||
288 | public function isDisplayed() |
||
292 | |||
293 | /** |
||
294 | * Set the notification message options. |
||
295 | * |
||
296 | * @param array $value |
||
297 | * |
||
298 | * @return void |
||
299 | */ |
||
300 | public function setOptions(array $value) |
||
304 | |||
305 | /** |
||
306 | * Get the notification message options. |
||
307 | * |
||
308 | * @return array |
||
309 | */ |
||
310 | public function getOptions() |
||
314 | |||
315 | /** |
||
316 | * To array method. |
||
317 | * |
||
318 | * @return array |
||
319 | */ |
||
320 | public function __toArray() |
||
333 | |||
334 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: