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