1 | <?php |
||
2 | |||
3 | namespace Toiba\FullCalendarBundle\Entity; |
||
4 | |||
5 | class Event |
||
6 | { |
||
7 | /** |
||
8 | * @var int|string |
||
9 | */ |
||
10 | protected $id = null; |
||
11 | |||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $title; |
||
16 | |||
17 | /** |
||
18 | * @var bool |
||
19 | */ |
||
20 | protected $allDay = true; |
||
21 | |||
22 | /** |
||
23 | * @var \DateTimeInterface |
||
24 | */ |
||
25 | protected $startDate; |
||
26 | |||
27 | /** |
||
28 | * @var \DateTimeInterface |
||
29 | */ |
||
30 | protected $endDate = null; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $url = null; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $className = null; |
||
41 | |||
42 | /** |
||
43 | * @var bool |
||
44 | */ |
||
45 | protected $editable = false; |
||
46 | |||
47 | /** |
||
48 | * @var bool |
||
49 | */ |
||
50 | protected $startEditable = false; |
||
51 | |||
52 | /** |
||
53 | * @var bool |
||
54 | */ |
||
55 | protected $durationEditable = false; |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $rendering = null; |
||
61 | |||
62 | /** |
||
63 | * @var bool |
||
64 | */ |
||
65 | protected $overlap = true; |
||
66 | |||
67 | /** |
||
68 | * @var array |
||
69 | */ |
||
70 | protected $constraint = null; |
||
71 | |||
72 | /** |
||
73 | * @var string |
||
74 | */ |
||
75 | protected $source = null; |
||
76 | |||
77 | /** |
||
78 | * @var string |
||
79 | */ |
||
80 | protected $color = null; |
||
81 | |||
82 | /** |
||
83 | * @var string |
||
84 | */ |
||
85 | protected $backgroundColor = null; |
||
86 | |||
87 | /** |
||
88 | * @var string |
||
89 | */ |
||
90 | protected $textColor = null; |
||
91 | |||
92 | /** |
||
93 | * @var array |
||
94 | */ |
||
95 | protected $customFields = []; |
||
96 | |||
97 | /** |
||
98 | * @param string $title |
||
99 | * @param \DateTimeInterface $start |
||
100 | * @param \DateTimeInterface $end |
||
101 | */ |
||
102 | 4 | public function __construct( |
|
103 | string $title, |
||
104 | \DateTimeInterface $start, |
||
105 | \DateTimeInterface $end = null |
||
106 | ) { |
||
107 | 4 | $this->setTitle($title); |
|
108 | 4 | $this->setStartDate($start); |
|
109 | 4 | $this->setEndDate($end); |
|
110 | 4 | } |
|
111 | |||
112 | /** |
||
113 | * @return null|int|string |
||
114 | */ |
||
115 | 2 | public function getId() |
|
116 | { |
||
117 | 2 | return $this->id; |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * @param null|int|string $id |
||
122 | */ |
||
123 | 1 | public function setId($id = null): void |
|
124 | { |
||
125 | 1 | $this->id = $id; |
|
126 | 1 | } |
|
127 | |||
128 | /** |
||
129 | * @return null|string |
||
130 | */ |
||
131 | 3 | public function getTitle(): ?string |
|
132 | { |
||
133 | 3 | return $this->title; |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * @param string $title |
||
138 | */ |
||
139 | 4 | public function setTitle(string $title): void |
|
140 | { |
||
141 | 4 | $this->title = $title; |
|
142 | 4 | } |
|
143 | |||
144 | /** |
||
145 | * @return bool |
||
146 | */ |
||
147 | 2 | public function isAllDay(): bool |
|
148 | { |
||
149 | 2 | return $this->allDay; |
|
150 | } |
||
151 | |||
152 | /** |
||
153 | * @param bool $allDay |
||
154 | */ |
||
155 | 1 | public function setAllDay(bool $allDay): void |
|
156 | { |
||
157 | 1 | $this->allDay = $allDay; |
|
158 | 1 | } |
|
159 | |||
160 | /** |
||
161 | * @return null|\DateTimeInterface |
||
162 | */ |
||
163 | 3 | public function getStartDate(): ?\DateTimeInterface |
|
164 | { |
||
165 | 3 | return $this->startDate; |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * @param \DateTimeInterface $startDate |
||
170 | */ |
||
171 | 4 | public function setStartDate(\DateTimeInterface $startDate): void |
|
172 | { |
||
173 | 4 | $this->startDate = $startDate; |
|
174 | 4 | } |
|
175 | |||
176 | /** |
||
177 | * @return null|\DateTimeInterface |
||
178 | */ |
||
179 | 3 | public function getEndDate(): ?\DateTimeInterface |
|
180 | { |
||
181 | 3 | return $this->endDate; |
|
182 | } |
||
183 | |||
184 | /** |
||
185 | * @param \DateTimeInterface $endDate |
||
186 | */ |
||
187 | 4 | public function setEndDate(\DateTimeInterface $endDate = null): void |
|
188 | { |
||
189 | 4 | if (null !== $endDate) { |
|
190 | 4 | $this->allDay = false; |
|
191 | } |
||
192 | 4 | $this->endDate = $endDate; |
|
193 | 4 | } |
|
194 | |||
195 | /** |
||
196 | * @return null|string |
||
197 | */ |
||
198 | 2 | public function getUrl(): ?string |
|
199 | { |
||
200 | 2 | return $this->url; |
|
201 | } |
||
202 | |||
203 | /** |
||
204 | * @param null|string $url |
||
205 | */ |
||
206 | 1 | public function setUrl(?string $url = null): void |
|
207 | { |
||
208 | 1 | $this->url = $url; |
|
209 | 1 | } |
|
210 | |||
211 | /** |
||
212 | * @return null|string |
||
213 | */ |
||
214 | 2 | public function getClassName(): ?string |
|
215 | { |
||
216 | 2 | return $this->className; |
|
217 | } |
||
218 | |||
219 | /** |
||
220 | * @param null|string $className |
||
221 | */ |
||
222 | 1 | public function setClassName(?string $className = null): void |
|
223 | { |
||
224 | 1 | $this->className = $className; |
|
225 | 1 | } |
|
226 | |||
227 | /** |
||
228 | * @return bool |
||
229 | */ |
||
230 | 2 | public function isEditable(): bool |
|
231 | { |
||
232 | 2 | return $this->editable; |
|
233 | } |
||
234 | |||
235 | /** |
||
236 | * @param bool $editable |
||
237 | */ |
||
238 | 1 | public function setEditable(bool $editable): void |
|
239 | { |
||
240 | 1 | $this->editable = $editable; |
|
241 | 1 | } |
|
242 | |||
243 | /** |
||
244 | * @return bool |
||
245 | */ |
||
246 | 2 | public function isStartEditable(): bool |
|
247 | { |
||
248 | 2 | return $this->startEditable; |
|
249 | } |
||
250 | |||
251 | /** |
||
252 | * @param bool $startEditable |
||
253 | */ |
||
254 | 1 | public function setStartEditable(bool $startEditable): void |
|
255 | { |
||
256 | 1 | $this->startEditable = $startEditable; |
|
257 | 1 | } |
|
258 | |||
259 | /** |
||
260 | * @return bool |
||
261 | */ |
||
262 | 2 | public function isDurationEditable(): bool |
|
263 | { |
||
264 | 2 | return $this->durationEditable; |
|
265 | } |
||
266 | |||
267 | /** |
||
268 | * @param bool $durationEditable |
||
269 | */ |
||
270 | 1 | public function setDurationEditable(bool $durationEditable): void |
|
271 | { |
||
272 | 1 | $this->durationEditable = $durationEditable; |
|
273 | 1 | } |
|
274 | |||
275 | /** |
||
276 | * @return null|string |
||
277 | */ |
||
278 | 2 | public function getRendering(): ?string |
|
279 | { |
||
280 | 2 | return $this->rendering; |
|
281 | } |
||
282 | |||
283 | /** |
||
284 | * @param null|string $rendering |
||
285 | */ |
||
286 | 1 | public function setRendering(?string $rendering = null): void |
|
287 | { |
||
288 | 1 | $this->rendering = $rendering; |
|
289 | 1 | } |
|
290 | |||
291 | /** |
||
292 | * @return bool |
||
293 | */ |
||
294 | 2 | public function isOverlap(): bool |
|
295 | { |
||
296 | 2 | return $this->overlap; |
|
297 | } |
||
298 | |||
299 | /** |
||
300 | * @param bool $overlap |
||
301 | */ |
||
302 | 1 | public function setOverlap(bool $overlap): void |
|
303 | { |
||
304 | 1 | $this->overlap = $overlap; |
|
305 | 1 | } |
|
306 | |||
307 | /** |
||
308 | * @return null|array |
||
309 | */ |
||
310 | 2 | public function getConstraint(): ?array |
|
311 | { |
||
312 | 2 | return $this->constraint; |
|
313 | } |
||
314 | |||
315 | /** |
||
316 | * @param null|array $constraint |
||
317 | */ |
||
318 | 1 | public function setConstraint(?array $constraint = null): void |
|
319 | { |
||
320 | 1 | $this->constraint = $constraint; |
|
321 | 1 | } |
|
322 | |||
323 | /** |
||
324 | * @return null|string |
||
325 | */ |
||
326 | 2 | public function getSource(): ?string |
|
327 | { |
||
328 | 2 | return $this->source; |
|
329 | } |
||
330 | |||
331 | /** |
||
332 | * @param null|string $source |
||
333 | */ |
||
334 | 1 | public function setSource(?string $source = null): void |
|
335 | { |
||
336 | 1 | $this->source = $source; |
|
337 | 1 | } |
|
338 | |||
339 | /** |
||
340 | * @return null|string |
||
341 | */ |
||
342 | 2 | public function getColor(): ?string |
|
343 | { |
||
344 | 2 | return $this->color; |
|
345 | } |
||
346 | |||
347 | /** |
||
348 | * @param null|string $color |
||
349 | */ |
||
350 | 1 | public function setColor(?string $color = null): void |
|
351 | { |
||
352 | 1 | $this->color = $color; |
|
353 | 1 | } |
|
354 | |||
355 | /** |
||
356 | * @return null|string |
||
357 | */ |
||
358 | 2 | public function getBackgroundColor(): ?string |
|
359 | { |
||
360 | 2 | return $this->backgroundColor; |
|
361 | } |
||
362 | |||
363 | /** |
||
364 | * @param null|string $backgroundColor |
||
365 | */ |
||
366 | 1 | public function setBackgroundColor(?string $backgroundColor = null): void |
|
367 | { |
||
368 | 1 | $this->backgroundColor = $backgroundColor; |
|
369 | 1 | } |
|
370 | |||
371 | /** |
||
372 | * @return null|string |
||
373 | */ |
||
374 | 2 | public function getTextColor(): ?string |
|
375 | { |
||
376 | 2 | return $this->textColor; |
|
377 | } |
||
378 | |||
379 | /** |
||
380 | * @param null|string $textColor |
||
381 | */ |
||
382 | 1 | public function setTextColor(?string $textColor = null): void |
|
383 | { |
||
384 | 1 | $this->textColor = $textColor; |
|
385 | 1 | } |
|
386 | |||
387 | /** |
||
388 | * @param string $name |
||
389 | * @param $value |
||
390 | * |
||
391 | * @return mixed |
||
392 | */ |
||
393 | 1 | public function setCustomField(string $name, $value): void |
|
394 | { |
||
395 | 1 | $this->customFields[$name] = $value; |
|
396 | 1 | } |
|
397 | |||
398 | /** |
||
399 | * @param string $name |
||
400 | * |
||
401 | * @return mixed |
||
402 | */ |
||
403 | 1 | public function getCustomFieldValue(string $name) |
|
404 | { |
||
405 | 1 | return $this->customFields[$name]; |
|
406 | } |
||
407 | |||
408 | /** |
||
409 | * @return array |
||
410 | */ |
||
411 | 2 | public function getCustomFields(): array |
|
412 | { |
||
413 | 2 | return $this->customFields; |
|
414 | } |
||
415 | |||
416 | /** |
||
417 | * @param string $name |
||
418 | * |
||
419 | * @return mixed |
||
420 | */ |
||
421 | 1 | public function removeCustomField(string $name) |
|
422 | { |
||
423 | 1 | if (!isset($this->customFields[$name]) && !array_key_exists($name, $this->customFields)) { |
|
424 | 1 | return null; |
|
425 | } |
||
426 | |||
427 | 1 | $removed = $this->customFields[$name]; |
|
428 | 1 | unset($this->customFields[$name]); |
|
429 | |||
430 | 1 | return $removed; |
|
431 | } |
||
432 | |||
433 | /** |
||
434 | * @return array |
||
435 | */ |
||
436 | 2 | public function toArray(): array |
|
437 | { |
||
438 | 2 | $event = []; |
|
439 | |||
440 | 2 | $event['title'] = $this->getTitle(); |
|
441 | 2 | $event['start'] = $this->getStartDate()->format('Y-m-d\\TH:i:sP'); |
|
442 | 2 | $event['allDay'] = $this->isAllDay(); |
|
443 | 2 | $event['editable'] = $this->isEditable(); |
|
444 | 2 | $event['startEditable'] = $this->isStartEditable(); |
|
445 | 2 | $event['durationEditable'] = $this->isDurationEditable(); |
|
446 | 2 | $event['overlap'] = $this->isOverlap(); |
|
447 | |||
448 | 2 | if (null !== $this->getId()) { |
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
449 | 1 | $event['id'] = $this->getId(); |
|
450 | } |
||
451 | |||
452 | 2 | if (null != $this->getUrl()) { |
|
453 | 1 | $event['url'] = $this->getUrl(); |
|
454 | } |
||
455 | |||
456 | 2 | if (null != $this->getBackgroundColor()) { |
|
457 | 1 | $event['backgroundColor'] = $this->getBackgroundColor(); |
|
458 | } |
||
459 | |||
460 | 2 | if (null != $this->getTextColor()) { |
|
461 | 1 | $event['textColor'] = $this->getTextColor(); |
|
462 | } |
||
463 | |||
464 | 2 | if (null != $this->getClassName()) { |
|
465 | 1 | $event['className'] = $this->getClassName(); |
|
466 | } |
||
467 | |||
468 | 2 | if (null != $this->getEndDate()) { |
|
469 | 2 | $event['end'] = $this->getEndDate()->format('Y-m-d\\TH:i:sP'); |
|
470 | } |
||
471 | |||
472 | 2 | if (null != $this->getRendering()) { |
|
473 | 1 | $event['rendering'] = $this->getRendering(); |
|
474 | } |
||
475 | |||
476 | 2 | if (null != $this->getConstraint()) { |
|
477 | 1 | $event['constraint'] = $this->getConstraint(); |
|
478 | } |
||
479 | |||
480 | 2 | if (null != $this->getSource()) { |
|
481 | 1 | $event['source'] = $this->getSource(); |
|
482 | } |
||
483 | |||
484 | 2 | if (null != $this->getColor()) { |
|
485 | 1 | $event['color'] = $this->getColor(); |
|
486 | } |
||
487 | |||
488 | 2 | foreach ($this->getCustomFields() as $field => $value) { |
|
489 | 1 | $event[$field] = $value; |
|
490 | } |
||
491 | |||
492 | 2 | return $event; |
|
493 | } |
||
494 | } |
||
495 |