1 | <?php |
||
23 | class Notice |
||
24 | { |
||
25 | /** |
||
26 | * @var int |
||
27 | */ |
||
28 | const STATUS_CREATED = 0; |
||
29 | |||
30 | /** |
||
31 | * @var int |
||
32 | */ |
||
33 | const STATUS_SHOWN = 1; |
||
34 | |||
35 | /** |
||
36 | * @var int |
||
37 | */ |
||
38 | const STATUS_CLOSED = 2; |
||
39 | |||
40 | /** |
||
41 | * @var int |
||
42 | */ |
||
43 | const DEFAULT_LIFETIME = 300; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | const DEFAULT_TYPE = 'no_type'; |
||
49 | |||
50 | /** |
||
51 | * @ORM\Id |
||
52 | * @ORM\GeneratedValue |
||
53 | * @ORM\Column(type="integer") |
||
54 | * |
||
55 | * @var int |
||
56 | */ |
||
57 | protected $id; |
||
58 | |||
59 | /** |
||
60 | * @ORM\Column(type="text") |
||
61 | * @Assert\NotBlank() |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $message = ''; |
||
66 | |||
67 | /** |
||
68 | * @ORM\Column(type="datetime", nullable=true) |
||
69 | * @Assert\DateTime() |
||
70 | * |
||
71 | * @var \DateTime|null |
||
72 | */ |
||
73 | protected $date_closed = null; |
||
74 | |||
75 | /** |
||
76 | * @ORM\Column(type="datetime") |
||
77 | * @Assert\DateTime() |
||
78 | * |
||
79 | * @var \DateTime |
||
80 | */ |
||
81 | protected $date_created; |
||
82 | |||
83 | /** |
||
84 | * Date start show notice. |
||
85 | * |
||
86 | * @ORM\Column(type="datetime") |
||
87 | * @Assert\DateTime() |
||
88 | * |
||
89 | * @var \DateTime |
||
90 | */ |
||
91 | protected $date_start; |
||
92 | |||
93 | /** |
||
94 | * @ORM\Column(type="integer") |
||
95 | * @Assert\NotBlank() |
||
96 | * @Assert\Type(type="integer", message="The value {{ value }} is not a valid {{ type }}.") |
||
97 | * |
||
98 | * @var int |
||
99 | */ |
||
100 | protected $lifetime = self::DEFAULT_LIFETIME; |
||
101 | |||
102 | /** |
||
103 | * @ORM\Column(type="integer") |
||
104 | * @Assert\Choice(callback = "getStatuses") |
||
105 | * |
||
106 | * @var int |
||
107 | */ |
||
108 | protected $status = self::STATUS_CREATED; |
||
109 | |||
110 | /** |
||
111 | * @ORM\Column(type="string", length=64) |
||
112 | * @Assert\NotBlank() |
||
113 | * |
||
114 | * @var string |
||
115 | */ |
||
116 | protected $type = self::DEFAULT_TYPE; |
||
117 | |||
118 | 24 | public function __construct() |
|
122 | |||
123 | /** |
||
124 | * Notice shown. |
||
125 | */ |
||
126 | 2 | public function shown() |
|
127 | { |
||
128 | 2 | if (is_null($this->date_closed)) { |
|
129 | 1 | $this->date_closed = new \DateTime(); |
|
130 | 1 | $this->date_closed->modify(sprintf('+%s seconds', $this->lifetime)); |
|
131 | } |
||
132 | 2 | $this->status = self::STATUS_SHOWN; |
|
133 | 2 | } |
|
134 | |||
135 | /** |
||
136 | * @return int |
||
137 | */ |
||
138 | 1 | public function getId() |
|
142 | |||
143 | /** |
||
144 | * @param string $message |
||
145 | * |
||
146 | * @return Notice |
||
147 | */ |
||
148 | 1 | public function setMessage($message) |
|
149 | { |
||
150 | 1 | $this->message = $message; |
|
151 | |||
152 | 1 | return $this; |
|
153 | } |
||
154 | |||
155 | /** |
||
156 | * @return string |
||
157 | */ |
||
158 | 1 | public function getMessage() |
|
159 | { |
||
160 | 1 | return $this->message; |
|
161 | } |
||
162 | |||
163 | /** |
||
164 | * @param \DateTime $date_closed |
||
165 | * |
||
166 | * @return Notice |
||
167 | */ |
||
168 | 2 | public function setDateClosed(\DateTime $date_closed) |
|
169 | { |
||
170 | 2 | $this->date_closed = clone $date_closed; |
|
171 | |||
172 | 2 | return $this; |
|
173 | } |
||
174 | |||
175 | /** |
||
176 | * @return \DateTime|null |
||
177 | */ |
||
178 | 3 | public function getDateClosed() |
|
179 | { |
||
180 | 3 | return $this->date_closed ? clone $this->date_closed : null; |
|
181 | } |
||
182 | |||
183 | /** |
||
184 | * @return \DateTime |
||
185 | */ |
||
186 | 1 | public function getDateCreated() |
|
187 | { |
||
188 | 1 | return clone $this->date_created; |
|
189 | } |
||
190 | |||
191 | /** |
||
192 | * @param \DateTime $date_start |
||
193 | * |
||
194 | * @return Notice |
||
195 | */ |
||
196 | 1 | public function setDateStart(\DateTime $date_start) |
|
197 | { |
||
198 | 1 | $this->date_start = clone $date_start; |
|
199 | |||
200 | 1 | return $this; |
|
201 | } |
||
202 | |||
203 | /** |
||
204 | * @return \DateTime |
||
205 | */ |
||
206 | 2 | public function getDateStart() |
|
210 | |||
211 | /** |
||
212 | * @param int $lifetime |
||
213 | * |
||
214 | * @return Notice |
||
215 | */ |
||
216 | 1 | public function setLifetime($lifetime) |
|
217 | { |
||
218 | 1 | $this->lifetime = $lifetime; |
|
219 | |||
220 | 1 | return $this; |
|
221 | } |
||
222 | |||
223 | /** |
||
224 | * @return int |
||
225 | */ |
||
226 | 2 | public function getLifetime() |
|
227 | { |
||
228 | 2 | return $this->lifetime; |
|
229 | } |
||
230 | |||
231 | /** |
||
232 | * @param int $status |
||
233 | * |
||
234 | * @return Notice |
||
235 | */ |
||
236 | 4 | public function setStatus($status) |
|
237 | { |
||
238 | 4 | $this->status = $status; |
|
239 | |||
240 | 4 | return $this; |
|
241 | } |
||
242 | |||
243 | /** |
||
244 | * @return int |
||
245 | */ |
||
246 | 6 | public function getStatus() |
|
247 | { |
||
248 | 6 | return $this->status; |
|
249 | } |
||
250 | |||
251 | /** |
||
252 | * @return int[] |
||
253 | */ |
||
254 | 1 | public static function getStatuses() |
|
255 | { |
||
256 | return [ |
||
257 | 1 | self::STATUS_CREATED, |
|
258 | 1 | self::STATUS_SHOWN, |
|
259 | 1 | self::STATUS_CLOSED, |
|
260 | ]; |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * @param string $type |
||
265 | * |
||
266 | * @return Notice |
||
267 | */ |
||
268 | 1 | public function setType($type) |
|
269 | { |
||
270 | 1 | $this->type = $type; |
|
271 | |||
272 | 1 | return $this; |
|
273 | } |
||
274 | |||
275 | /** |
||
276 | * @return string |
||
277 | */ |
||
278 | 1 | public function getType() |
|
282 | } |
||
283 |