Completed
Pull Request — master (#146)
by
unknown
01:38
created

Event::setCancelled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the eluceo/iCal package.
5
 *
6
 * (c) Markus Poerschke <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Eluceo\iCal\Component;
13
14
use Eluceo\iCal\Component;
15
use Eluceo\iCal\Property;
16
use Eluceo\iCal\Property\DateTimeProperty;
17
use Eluceo\iCal\Property\DateTimesProperty;
18
use Eluceo\iCal\Property\Event\Attachment;
19
use Eluceo\iCal\Property\Event\Attendees;
20
use Eluceo\iCal\Property\Event\Geo;
21
use Eluceo\iCal\Property\Event\Organizer;
22
use Eluceo\iCal\Property\Event\RecurrenceId;
23
use Eluceo\iCal\Property\Event\RecurrenceRule;
24
use Eluceo\iCal\Property\RawStringValue;
25
use Eluceo\iCal\PropertyBag;
26
27
/**
28
 * Implementation of the EVENT component.
29
 */
30
class Event extends Component
31
{
32
    const TIME_TRANSPARENCY_OPAQUE = 'OPAQUE';
33
    const TIME_TRANSPARENCY_TRANSPARENT = 'TRANSPARENT';
34
35
    const STATUS_TENTATIVE = 'TENTATIVE';
36
    const STATUS_CONFIRMED = 'CONFIRMED';
37
    const STATUS_CANCELLED = 'CANCELLED';
38
39
    const MS_BUSYSTATUS_FREE = 'FREE';
40
    const MS_BUSYSTATUS_TENTATIVE = 'TENTATIVE';
41
    const MS_BUSYSTATUS_BUSY = 'BUSY';
42
    const MS_BUSYSTATUS_OOF = 'OOF';
43
44
    /**
45
     * @var string
46
     */
47
    protected $uniqueId;
48
49
    /**
50
     * The property indicates the date/time that the instance of
51
     * the iCalendar object was created.
52
     *
53
     * The value MUST be specified in the UTC time format.
54
     *
55
     * @var \DateTime
56
     */
57
    protected $dtStamp;
58
59
    /**
60
     * @var \DateTime
61
     */
62
    protected $dtStart;
63
64
    /**
65
     * Preferentially chosen over the duration if both are set.
66
     *
67
     * @var \DateTime
68
     */
69
    protected $dtEnd;
70
71
    /**
72
     * @var \DateInterval
73
     */
74
    protected $duration;
75
76
    /**
77
     * @var bool
78
     */
79
    protected $noTime = false;
80
81
    /**
82
     * @var string
83
     */
84
    protected $msBusyStatus = null;
85
86
    /**
87
     * @var string
88
     */
89
    protected $url;
90
91
    /**
92
     * @var string
93
     */
94
    protected $location;
95
96
    /**
97
     * @var string
98
     */
99
    protected $locationTitle;
100
101
    /**
102
     * @var Geo
103
     */
104
    protected $locationGeo;
105
106
    /**
107
     * @var string
108
     */
109
    protected $summary;
110
111
    /**
112
     * @var Organizer
113
     */
114
    protected $organizer;
115
116
    /**
117
     * @see https://tools.ietf.org/html/rfc5545#section-3.8.2.7
118
     *
119
     * @var string
120
     */
121
    protected $transparency = self::TIME_TRANSPARENCY_OPAQUE;
122
123
    /**
124
     * If set to true the timezone will be added to the event.
125
     *
126
     * @var bool
127
     */
128
    protected $useTimezone = false;
129
130
    /**
131
     * If set will be used as the timezone identifier.
132
     *
133
     * @var string
134
     */
135
    protected $timezoneString = '';
136
137
    /**
138
     * @var int
139
     */
140
    protected $sequence = 0;
141
142
    /**
143
     * @var Attendees
144
     */
145
    protected $attendees;
146
147
    /**
148
     * @var string
149
     */
150
    protected $description;
151
152
    /**
153
     * @var string
154
     */
155
    protected $descriptionHTML;
156
157
    /**
158
     * @var string
159
     */
160
    protected $status;
161
162
    /**
163
     * @var RecurrenceRule
164
     */
165
    protected $recurrenceRule;
166
167
    /**
168
     * @var array
169
     */
170
    protected $recurrenceRules = [];
171
172
    /**
173
     * This property specifies the date and time that the calendar
174
     * information was created.
175
     *
176
     * The value MUST be specified in the UTC time format.
177
     *
178
     * @var \DateTime
179
     */
180
    protected $created;
181
182
    /**
183
     * The property specifies the date and time that the information
184
     * associated with the calendar component was last revised.
185
     *
186
     * The value MUST be specified in the UTC time format.
187
     *
188
     * @var \DateTime
189
     */
190
    protected $modified;
191
192
    /**
193
     * Indicates if the UTC time should be used or not.
194
     *
195
     * @var bool
196
     */
197
    protected $useUtc = true;
198
199
    /**
200
     * @var bool
201
     */
202
    protected $cancelled;
203
204
    /**
205
     * This property is used to specify categories or subtypes
206
     * of the calendar component.  The categories are useful in searching
207
     * for a calendar component of a particular type and category.
208
     *
209
     * @see https://tools.ietf.org/html/rfc5545#section-3.8.1.2
210
     *
211
     * @var array
212
     */
213
    protected $categories;
214
215
    /**
216
     * https://tools.ietf.org/html/rfc5545#section-3.8.1.3.
217
     *
218
     * @var bool
219
     */
220
    protected $isPrivate = false;
221
222
    /**
223
     * Dates to be excluded from a series of events.
224
     *
225
     * @var \DateTimeInterface[]
226
     */
227
    protected $exDates = [];
228
229
    /**
230
     * @var RecurrenceId
231
     */
232
    protected $recurrenceId;
233
234
    /**
235
     * @var Attachment[]
236
     */
237
    protected $attachments = [];
238
239 28
    public function __construct(string $uniqueId = null)
240
    {
241 28
        if (null == $uniqueId) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $uniqueId of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
242 4
            $uniqueId = uniqid();
243
        }
244
245 28
        $this->uniqueId = $uniqueId;
246 28
        $this->attendees = new Attendees();
247 28
    }
248
249
    /**
250
     * {@inheritdoc}
251
     */
252 7
    public function getType()
253
    {
254 7
        return 'VEVENT';
255
    }
256
257
    /**
258
     * {@inheritdoc}
259
     */
260 18
    public function buildPropertyBag()
261
    {
262 18
        $propertyBag = new PropertyBag();
263
264
        // mandatory information
265 18
        $propertyBag->set('UID', $this->uniqueId);
266
267 18
        $propertyBag->add(new DateTimeProperty('DTSTART', $this->dtStart, $this->noTime, $this->useTimezone, $this->useUtc, $this->timezoneString));
268 18
        $propertyBag->set('SEQUENCE', $this->sequence);
269 18
        $propertyBag->set('TRANSP', $this->transparency);
270
271 18
        if ($this->status) {
272
            $propertyBag->set('STATUS', $this->status);
273
        }
274
275
        // An event can have a 'dtend' or 'duration', but not both.
276 18
        if ($this->dtEnd !== null) {
277 4
            $dtEnd = clone $this->dtEnd;
278 4
            if ($this->noTime === true) {
279
                $dtEnd = $dtEnd->add(new \DateInterval('P1D'));
280
            }
281 4
            $propertyBag->add(new DateTimeProperty('DTEND', $dtEnd, $this->noTime, $this->useTimezone, $this->useUtc, $this->timezoneString));
282 14
        } elseif ($this->duration !== null) {
283 1
            $propertyBag->set('DURATION', $this->duration->format('P%dDT%hH%iM%sS'));
284
        }
285
286
        // optional information
287 18
        if (null != $this->url) {
288 1
            $propertyBag->set('URL', $this->url);
289
        }
290
291 18
        if (null != $this->location) {
292 2
            $propertyBag->set('LOCATION', $this->location);
293
294 2
            if (null != $this->locationGeo) {
295 1
                $propertyBag->add(
296 1
                    new Property(
297 1
                        'X-APPLE-STRUCTURED-LOCATION',
298 1
                        new RawStringValue('geo:' . $this->locationGeo->getGeoLocationAsString(',')),
299
                        [
300 1
                            'VALUE' => 'URI',
301 1
                            'X-ADDRESS' => $this->location,
302 1
                            'X-APPLE-RADIUS' => 49,
303 1
                            'X-TITLE' => $this->locationTitle,
304
                        ]
305
                    )
306
                );
307
            }
308
        }
309
310 18
        if (null != $this->locationGeo) {
311 2
            $propertyBag->add($this->locationGeo);
312
        }
313
314 18
        if (null != $this->summary) {
315 1
            $propertyBag->set('SUMMARY', $this->summary);
316
        }
317
318 18
        if (null != $this->attendees) {
319 18
            $propertyBag->add($this->attendees);
320
        }
321
322 18
        $propertyBag->set('CLASS', $this->isPrivate ? 'PRIVATE' : 'PUBLIC');
323
324 18
        if (null != $this->description) {
325 4
            $propertyBag->set('DESCRIPTION', $this->description);
326
        }
327
328 18
        if (null != $this->descriptionHTML) {
329
            $propertyBag->add(
330
                new Property(
331
                    'X-ALT-DESC',
332
                    $this->descriptionHTML,
333
                    [
334
                        'FMTTYPE' => 'text/html',
335
                    ]
336
                )
337
            );
338
        }
339
340 18
        if (null != $this->recurrenceRule) {
341
            $propertyBag->set('RRULE', $this->recurrenceRule);
342
        }
343
344 18
        foreach ($this->recurrenceRules as $recurrenceRule) {
345
            $propertyBag->set('RRULE', $recurrenceRule);
346
        }
347
348 18
        if (null != $this->recurrenceId) {
349
            $this->recurrenceId->applyTimeSettings($this->noTime, $this->useTimezone, $this->useUtc, $this->timezoneString);
350
            $propertyBag->add($this->recurrenceId);
351
        }
352
353 18
        if (!empty($this->exDates)) {
354
            $propertyBag->add(new DateTimesProperty('EXDATE', $this->exDates, $this->noTime, $this->useTimezone, $this->useUtc, $this->timezoneString));
355
        }
356
357 18
        if ($this->cancelled) {
358
            $propertyBag->set('STATUS', 'CANCELLED');
359
        }
360
361 18
        if (null != $this->organizer) {
362 2
            $propertyBag->add($this->organizer);
363
        }
364
365 18
        if ($this->noTime) {
366 1
            $propertyBag->set('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE');
367
        }
368
369 18
        if (null != $this->msBusyStatus) {
370 1
            $propertyBag->set('X-MICROSOFT-CDO-BUSYSTATUS', $this->msBusyStatus);
371 1
            $propertyBag->set('X-MICROSOFT-CDO-INTENDEDSTATUS', $this->msBusyStatus);
372
        }
373
374 18
        if (null != $this->categories) {
375
            $propertyBag->set('CATEGORIES', $this->categories);
376
        }
377
378 18
        $propertyBag->add(
379 18
            new DateTimeProperty('DTSTAMP', $this->dtStamp ?: new \DateTimeImmutable(), false, false, true)
380
        );
381
382 18
        if ($this->created) {
383
            $propertyBag->add(new DateTimeProperty('CREATED', $this->created, false, false, true));
384
        }
385
386 18
        if ($this->modified) {
387
            $propertyBag->add(new DateTimeProperty('LAST-MODIFIED', $this->modified, false, false, true));
388
        }
389
390 18
        foreach ($this->attachments as $attachment) {
391
            $propertyBag->add($attachment);
392
        }
393
394 18
        return $propertyBag;
395
    }
396
397
    /**
398
     * @param $dtEnd
399
     *
400
     * @return $this
401
     */
402 5
    public function setDtEnd($dtEnd)
403
    {
404 5
        $this->dtEnd = $dtEnd;
405
406 5
        return $this;
407
    }
408
409 2
    public function getDtEnd()
410
    {
411 2
        return $this->dtEnd;
412
    }
413
414 5
    public function setDtStart($dtStart)
415
    {
416 5
        $this->dtStart = $dtStart;
417
418 5
        return $this;
419
    }
420
421 2
    public function getDtStart()
422
    {
423 2
        return $this->dtStart;
424
    }
425
426
    /**
427
     * @param $dtStamp
428
     *
429
     * @return $this
430
     */
431 1
    public function setDtStamp($dtStamp)
432
    {
433 1
        $this->dtStamp = $dtStamp;
434
435 1
        return $this;
436
    }
437
438
    /**
439
     * @param $duration
440
     *
441
     * @return $this
442
     */
443 1
    public function setDuration($duration)
444
    {
445 1
        $this->duration = $duration;
446
447 1
        return $this;
448
    }
449
450
    /**
451
     * @param string     $location
452
     * @param string     $title
453
     * @param Geo|string $geo
454
     *
455
     * @return $this
456
     */
457 3
    public function setLocation($location, $title = '', $geo = null)
458
    {
459 3
        if (is_scalar($geo)) {
460 1
            $geo = Geo::fromString($geo);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\Property\Event\Geo::fromString() has been deprecated with message: This method is used to allow backwards compatibility for Event::setLocation

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
461 2
        } elseif (!is_null($geo) && !$geo instanceof Geo) {
462 1
            $className = get_class($geo);
463 1
            throw new \InvalidArgumentException("The parameter 'geo' must be a string or an instance of " . Geo::class . " but an instance of {$className} was given.");
464
        }
465
466 2
        $this->location = $location;
467 2
        $this->locationTitle = $title;
468 2
        $this->locationGeo = $geo;
469
470 2
        return $this;
471
    }
472
473
    /**
474
     * @return $this
475
     */
476 1
    public function setGeoLocation(Geo $geoProperty)
477
    {
478 1
        $this->locationGeo = $geoProperty;
479
480 1
        return $this;
481
    }
482
483
    /**
484
     * @param $noTime
485
     *
486
     * @return $this
487
     */
488 1
    public function setNoTime($noTime)
489
    {
490 1
        $this->noTime = $noTime;
491
492 1
        return $this;
493
    }
494
495
    /**
496
     * @param $msBusyStatus
497
     *
498
     * @return $this
499
     *
500
     * @throws \InvalidArgumentException
501
     */
502 2 View Code Duplication
    public function setMsBusyStatus($msBusyStatus)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
503
    {
504 2
        $msBusyStatus = strtoupper($msBusyStatus);
505 2
        if ($msBusyStatus == self::MS_BUSYSTATUS_FREE
506
            || $msBusyStatus == self::MS_BUSYSTATUS_TENTATIVE
507
            || $msBusyStatus == self::MS_BUSYSTATUS_BUSY
508 2
            || $msBusyStatus == self::MS_BUSYSTATUS_OOF
509
        ) {
510 2
            $this->msBusyStatus = $msBusyStatus;
511
        } else {
512
            throw new \InvalidArgumentException('Invalid value for status');
513
        }
514
515 2
        return $this;
516
    }
517
518
    /**
519
     * @return string|null
520
     */
521 1
    public function getMsBusyStatus()
522
    {
523 1
        return $this->msBusyStatus;
524
    }
525
526
    /**
527
     * @param int $sequence
528
     *
529
     * @return $this
530
     */
531 2
    public function setSequence($sequence)
532
    {
533 2
        $this->sequence = $sequence;
534
535 2
        return $this;
536
    }
537
538
    /**
539
     * @return int
540
     */
541 1
    public function getSequence()
542
    {
543 1
        return $this->sequence;
544
    }
545
546
    /**
547
     * @return $this
548
     */
549 2
    public function setOrganizer(Organizer $organizer)
550
    {
551 2
        $this->organizer = $organizer;
552
553 2
        return $this;
554
    }
555
556
    /**
557
     * @param $summary
558
     *
559
     * @return $this
560
     */
561 1
    public function setSummary($summary)
562
    {
563 1
        $this->summary = $summary;
564
565 1
        return $this;
566
    }
567
568
    /**
569
     * @param $uniqueId
570
     *
571
     * @return $this
572
     */
573 1
    public function setUniqueId($uniqueId)
574
    {
575 1
        $this->uniqueId = $uniqueId;
576
577 1
        return $this;
578
    }
579
580
    /**
581
     * @return string
582
     */
583 2
    public function getUniqueId()
584
    {
585 2
        return $this->uniqueId;
586
    }
587
588
    /**
589
     * @param $url
590
     *
591
     * @return $this
592
     */
593 1
    public function setUrl($url)
594
    {
595 1
        $this->url = $url;
596
597 1
        return $this;
598
    }
599
600
    /**
601
     * @param $useTimezone
602
     *
603
     * @return $this
604
     */
605
    public function setUseTimezone($useTimezone)
606
    {
607
        $this->useTimezone = $useTimezone;
608
609
        return $this;
610
    }
611
612
    /**
613
     * @return bool
614
     */
615
    public function getUseTimezone()
616
    {
617
        return $this->useTimezone;
618
    }
619
620
    /**
621
     * @param $timezoneString
622
     *
623
     * @return $this
624
     */
625 2
    public function setTimezoneString($timezoneString)
626
    {
627 2
        $this->timezoneString = $timezoneString;
628
629 2
        return $this;
630
    }
631
632
    /**
633
     * @return bool
634
     */
635 1
    public function getTimezoneString()
636
    {
637 1
        return $this->timezoneString;
638
    }
639
640
    /**
641
     * @return $this
642
     */
643
    public function setAttendees(Attendees $attendees)
644
    {
645
        $this->attendees = $attendees;
646
647
        return $this;
648
    }
649
650
    /**
651
     * @param string $attendee
652
     * @param array  $params
653
     *
654
     * @return $this
655
     */
656
    public function addAttendee($attendee, $params = [])
657
    {
658
        $this->attendees->add($attendee, $params);
659
660
        return $this;
661
    }
662
663
    /**
664
     * @return Attendees
665
     */
666
    public function getAttendees(): Attendees
667
    {
668
        return $this->attendees;
669
    }
670
671
    /**
672
     * @param $description
673
     *
674
     * @return $this
675
     */
676 4
    public function setDescription($description)
677
    {
678 4
        $this->description = $description;
679
680 4
        return $this;
681
    }
682
683
    /**
684
     * @param $descriptionHTML
685
     *
686
     * @return $this
687
     */
688
    public function setDescriptionHTML($descriptionHTML)
689
    {
690
        $this->descriptionHTML = $descriptionHTML;
691
692
        return $this;
693
    }
694
695
    /**
696
     * @param bool $useUtc
697
     *
698
     * @return $this
699
     */
700
    public function setUseUtc($useUtc = true)
701
    {
702
        $this->useUtc = $useUtc;
703
704
        return $this;
705
    }
706
707
    /**
708
     * @return string
709
     */
710
    public function getDescription()
711
    {
712
        return $this->description;
713
    }
714
715
    /**
716
     * @return string
717
     */
718
    public function getDescriptionHTML()
719
    {
720
        return $this->descriptionHTML;
721
    }
722
723
    /**
724
     * @param $status
725
     *
726
     * @return $this
727
     */
728
    public function setCancelled($status)
729
    {
730
        $this->cancelled = (bool) $status;
731
732
        return $this;
733
    }
734
735
    /**
736
     * @param $transparency
737
     *
738
     * @return $this
739
     *
740
     * @throws \InvalidArgumentException
741
     */
742 View Code Duplication
    public function setTimeTransparency($transparency)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
743
    {
744
        $transparency = strtoupper($transparency);
745
        if ($transparency === self::TIME_TRANSPARENCY_OPAQUE
746
            || $transparency === self::TIME_TRANSPARENCY_TRANSPARENT
747
        ) {
748
            $this->transparency = $transparency;
749
        } else {
750
            throw new \InvalidArgumentException('Invalid value for transparancy');
751
        }
752
753
        return $this;
754
    }
755
756
    /**
757
     * @param $status
758
     *
759
     * @return $this
760
     *
761
     * @throws \InvalidArgumentException
762
     */
763 View Code Duplication
    public function setStatus($status)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
764
    {
765
        $status = strtoupper($status);
766
        if ($status == self::STATUS_CANCELLED
767
            || $status == self::STATUS_CONFIRMED
768
            || $status == self::STATUS_TENTATIVE
769
        ) {
770
            $this->status = $status;
771
        } else {
772
            throw new \InvalidArgumentException('Invalid value for status');
773
        }
774
775
        return $this;
776
    }
777
778
    /**
779
     * @deprecated Deprecated since version 0.11.0, to be removed in 1.0. Use addRecurrenceRule instead.
780
     *
781
     * @return $this
782
     */
783
    public function setRecurrenceRule(RecurrenceRule $recurrenceRule)
784
    {
785
        @trigger_error('setRecurrenceRule() is deprecated since version 0.11.0 and will be removed in 1.0. Use addRecurrenceRule instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
786
787
        $this->recurrenceRule = $recurrenceRule;
788
789
        return $this;
790
    }
791
792
    /**
793
     * @deprecated Deprecated since version 0.11.0, to be removed in 1.0. Use getRecurrenceRules instead.
794
     *
795
     * @return RecurrenceRule
796
     */
797
    public function getRecurrenceRule()
798
    {
799
        @trigger_error('getRecurrenceRule() is deprecated since version 0.11.0 and will be removed in 1.0. Use getRecurrenceRules instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
800
801
        return $this->recurrenceRule;
802
    }
803
804
    /**
805
     * @return $this
806
     */
807
    public function addRecurrenceRule(RecurrenceRule $recurrenceRule)
808
    {
809
        $this->recurrenceRules[] = $recurrenceRule;
810
811
        return $this;
812
    }
813
814
    /**
815
     * @return array
816
     */
817
    public function getRecurrenceRules()
818
    {
819
        return $this->recurrenceRules;
820
    }
821
822
    /**
823
     * @param $dtStamp
824
     *
825
     * @return $this
826
     */
827
    public function setCreated($dtStamp)
828
    {
829
        $this->created = $dtStamp;
830
831
        return $this;
832
    }
833
834
    /**
835
     * @param $dtStamp
836
     *
837
     * @return $this
838
     */
839
    public function setModified($dtStamp)
840
    {
841
        $this->modified = $dtStamp;
842
843
        return $this;
844
    }
845
846
    /**
847
     * @param $categories
848
     *
849
     * @return $this
850
     */
851
    public function setCategories($categories)
852
    {
853
        $this->categories = $categories;
854
855
        return $this;
856
    }
857
858
    /**
859
     * Sets the event privacy.
860
     *
861
     * @param bool $flag
862
     *
863
     * @return $this
864
     */
865
    public function setIsPrivate($flag)
866
    {
867
        $this->isPrivate = (bool) $flag;
868
869
        return $this;
870
    }
871
872
    /**
873
     * @return \Eluceo\iCal\Component\Event
874
     */
875
    public function addExDate(\DateTimeInterface $dateTime)
876
    {
877
        $this->exDates[] = $dateTime;
878
879
        return $this;
880
    }
881
882
    /**
883
     * @return \DateTimeInterface[]
884
     */
885
    public function getExDates()
886
    {
887
        return $this->exDates;
888
    }
889
890
    /**
891
     * @param \DateTimeInterface[]
892
     *
893
     * @return \Eluceo\iCal\Component\Event
894
     */
895
    public function setExDates(array $exDates)
896
    {
897
        $this->exDates = $exDates;
898
899
        return $this;
900
    }
901
902
    /**
903
     * @return \Eluceo\iCal\Property\Event\RecurrenceId
904
     */
905
    public function getRecurrenceId()
906
    {
907
        return $this->recurrenceId;
908
    }
909
910
    /**
911
     * @return \Eluceo\iCal\Component\Event
912
     */
913
    public function setRecurrenceId(RecurrenceId $recurrenceId)
914
    {
915
        $this->recurrenceId = $recurrenceId;
916
917
        return $this;
918
    }
919
920
    /**
921
     * @param array $attachment
922
     *
923
     * @return $this
924
     */
925 1
    public function addAttachment(Attachment $attachment)
926
    {
927 1
        $this->attachments[] = $attachment;
928
929 1
        return $this;
930
    }
931
932
    /**
933
     * @return array
934
     */
935
    public function getAttachments()
936
    {
937
        return $this->attachments;
938
    }
939
940
    public function addUrlAttachment(string $url)
941
    {
942
        $this->addAttachment(new Attachment($url));
943
    }
944
}
945