From eaaad976cf32af27d700be2bc9fdb9c01bf83295 Mon Sep 17 00:00:00 2001 From: Romain Perez Date: Fri, 27 Sep 2024 15:09:01 +0200 Subject: [PATCH] restore lost event property X-MICROSOFT-CDO-BUSYSTATUS --- CHANGELOG.md | 2 + src/Domain/Entity/Event.php | 28 +++++++++++++ src/Domain/Enum/MsBusyStatus.php | 42 +++++++++++++++++++ src/Presentation/Factory/EventFactory.php | 27 ++++++++++++ tests/Integration/EventsGeneratorTest.php | 10 ++++- .../Presentation/Factory/EventFactoryTest.php | 24 +++++++++++ website/docs/component-event.md | 12 ++++++ 7 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/Domain/Enum/MsBusyStatus.php diff --git a/CHANGELOG.md b/CHANGELOG.md index cf60104d..24bbaf7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Re-Add property `X-MICROSOFT-CDO-BUSYSTATUS` that was added in 0.16.0 and then lost + ## [2.14.0] - 2024-07-11 ### Fixed diff --git a/src/Domain/Entity/Event.php b/src/Domain/Entity/Event.php index fce585b1..72ba42db 100644 --- a/src/Domain/Entity/Event.php +++ b/src/Domain/Entity/Event.php @@ -12,6 +12,7 @@ namespace Eluceo\iCal\Domain\Entity; use Eluceo\iCal\Domain\Enum\EventStatus; +use Eluceo\iCal\Domain\Enum\MsBusyStatus; use Eluceo\iCal\Domain\ValueObject\Alarm; use Eluceo\iCal\Domain\ValueObject\Attachment; use Eluceo\iCal\Domain\ValueObject\Category; @@ -34,6 +35,7 @@ class Event private ?Organizer $organizer = null; private ?Timestamp $lastModified = null; private ?EventStatus $status = null; + private ?MsBusyStatus $msBusyStatus = null; /** * @var array @@ -347,4 +349,30 @@ public function unsetStatus(): self return $this; } + + public function getMsBusyStatus(): MsBusyStatus + { + assert($this->msBusyStatus !== null); + + return $this->msBusyStatus; + } + + public function hasMsBusyStatus(): bool + { + return $this->msBusyStatus !== null; + } + + public function setMsBusyStatus(MsBusyStatus $msBusyStatus): self + { + $this->msBusyStatus = $msBusyStatus; + + return $this; + } + + public function unsetMsBusyStatus(): self + { + $this->msBusyStatus = null; + + return $this; + } } diff --git a/src/Domain/Enum/MsBusyStatus.php b/src/Domain/Enum/MsBusyStatus.php new file mode 100644 index 00000000..37898bb4 --- /dev/null +++ b/src/Domain/Enum/MsBusyStatus.php @@ -0,0 +1,42 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +declare(strict_types=1); + +namespace Eluceo\iCal\Domain\Enum; + +final class MsBusyStatus +{ + private static ?self $free = null; + private static ?self $tentative = null; + private static ?self $busy = null; + private static ?self $oof = null; + + public static function FREE(): self + { + return self::$free ??= new self(); + } + + public static function TENTATIVE(): self + { + return self::$tentative ??= new self(); + } + + public static function BUSY(): self + { + return self::$busy ??= new self(); + } + + public static function OOF(): self + { + return self::$oof ??= new self(); + } +} diff --git a/src/Presentation/Factory/EventFactory.php b/src/Presentation/Factory/EventFactory.php index 2f834b2a..194e85a5 100644 --- a/src/Presentation/Factory/EventFactory.php +++ b/src/Presentation/Factory/EventFactory.php @@ -15,6 +15,7 @@ use Eluceo\iCal\Domain\Collection\Events; use Eluceo\iCal\Domain\Entity\Event; use Eluceo\iCal\Domain\Enum\EventStatus; +use Eluceo\iCal\Domain\Enum\MsBusyStatus; use Eluceo\iCal\Domain\ValueObject\Alarm; use Eluceo\iCal\Domain\ValueObject\Attachment; use Eluceo\iCal\Domain\ValueObject\MultiDay; @@ -125,6 +126,11 @@ protected function getProperties(Event $event): Generator yield new Property('STATUS', $this->getEventStatusTextValue($event->getStatus())); } + if ($event->hasMsBusyStatus()) { + yield new Property('X-MICROSOFT-CDO-BUSYSTATUS', $this->getEventMsBusyStatusTextValue($event->getMsBusyStatus())); + yield new Property('X-MICROSOFT-CDO-INTENDEDSTATUS', $this->getEventMsBusyStatusTextValue($event->getMsBusyStatus())); + } + foreach ($event->getAttachments() as $attachment) { yield from $this->getAttachmentProperties($attachment); } @@ -278,4 +284,25 @@ private function getEventStatusTextValue(EventStatus $status): TextValue throw new UnexpectedValueException(sprintf('The enum %s resulted into an unknown status type value that is not yet implemented.', EventStatus::class)); } + + private function getEventMsBusyStatusTextValue(MsBusyStatus $msBusyStatus): TextValue + { + if ($msBusyStatus === MsBusyStatus::FREE()) { + return new TextValue('FREE'); + } + + if ($msBusyStatus === MsBusyStatus::BUSY()) { + return new TextValue('BUSY'); + } + + if ($msBusyStatus === MsBusyStatus::TENTATIVE()) { + return new TextValue('TENTATIVE'); + } + + if ($msBusyStatus === MsBusyStatus::OOF()) { + return new TextValue('OOF'); + } + + throw new UnexpectedValueException(sprintf('The enum %s resulted into an unknown status type value that is not yet implemented.', MsBusyStatus::class)); + } } diff --git a/tests/Integration/EventsGeneratorTest.php b/tests/Integration/EventsGeneratorTest.php index 16082a03..7dbbc139 100644 --- a/tests/Integration/EventsGeneratorTest.php +++ b/tests/Integration/EventsGeneratorTest.php @@ -16,6 +16,7 @@ use DateTimeZone; use Eluceo\iCal\Domain\Entity\Calendar; use Eluceo\iCal\Domain\Entity\Event; +use Eluceo\iCal\Domain\Enum\MsBusyStatus; use Eluceo\iCal\Domain\ValueObject\Date; use Eluceo\iCal\Domain\ValueObject\SingleDay; use Eluceo\iCal\Domain\ValueObject\Timestamp; @@ -36,7 +37,8 @@ public function testEventsGeneratorCreatesIcsContent(): void yield (new Event(new UniqueIdentifier('event-' . $i))) ->touch($timestamp) ->setSummary('Event ' . $i) - ->setOccurrence(new SingleDay(new Date($day))); + ->setOccurrence(new SingleDay(new Date($day))) + ->setMsBusyStatus(MsBusyStatus::BUSY()); $day = $day->add($dayInterval); } }; @@ -55,18 +57,24 @@ public function testEventsGeneratorCreatesIcsContent(): void 'DTSTAMP:20200101T150000Z', 'SUMMARY:Event 0', 'DTSTART;VALUE=DATE:20200101', + 'X-MICROSOFT-CDO-BUSYSTATUS:BUSY', + 'X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY', 'END:VEVENT', 'BEGIN:VEVENT', 'UID:event-1', 'DTSTAMP:20200101T150000Z', 'SUMMARY:Event 1', 'DTSTART;VALUE=DATE:20200102', + 'X-MICROSOFT-CDO-BUSYSTATUS:BUSY', + 'X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY', 'END:VEVENT', 'BEGIN:VEVENT', 'UID:event-2', 'DTSTAMP:20200101T150000Z', 'SUMMARY:Event 2', 'DTSTART;VALUE=DATE:20200103', + 'X-MICROSOFT-CDO-BUSYSTATUS:BUSY', + 'X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY', 'END:VEVENT', 'END:VCALENDAR', ]; diff --git a/tests/Unit/Presentation/Factory/EventFactoryTest.php b/tests/Unit/Presentation/Factory/EventFactoryTest.php index a5e953ad..de61a2d5 100644 --- a/tests/Unit/Presentation/Factory/EventFactoryTest.php +++ b/tests/Unit/Presentation/Factory/EventFactoryTest.php @@ -17,6 +17,7 @@ use Eluceo\iCal\Domain\Entity\Event; use Eluceo\iCal\Domain\Enum\CalendarUserType; use Eluceo\iCal\Domain\Enum\EventStatus; +use Eluceo\iCal\Domain\Enum\MsBusyStatus; use Eluceo\iCal\Domain\Enum\ParticipationStatus; use Eluceo\iCal\Domain\Enum\RoleType; use Eluceo\iCal\Domain\ValueObject\Attachment; @@ -561,4 +562,27 @@ private static function assertEventRendersCorrect(Event $event, array $expected) $resultAsArray = array_slice($resultAsArray, 3, -2); self::assertSame($expected, $resultAsArray); } + + /** + * @return array + */ + public static function msBusyStatusProvider(): array + { + return [ + [MsBusyStatus::FREE(), ['X-MICROSOFT-CDO-BUSYSTATUS:FREE', 'X-MICROSOFT-CDO-INTENDEDSTATUS:FREE']], + [MsBusyStatus::BUSY(), ['X-MICROSOFT-CDO-BUSYSTATUS:BUSY', 'X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY']], + [MsBusyStatus::TENTATIVE(), ['X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE', 'X-MICROSOFT-CDO-INTENDEDSTATUS:TENTATIVE']], + [MsBusyStatus::OOF(), ['X-MICROSOFT-CDO-BUSYSTATUS:OOF', 'X-MICROSOFT-CDO-INTENDEDSTATUS:OOF']], + ]; + } + + /** + * @dataProvider msBusyStatusProvider + */ + public function testMsBusyStatus(MsBusyStatus $msBusyStatus, array $properties): void + { + $event = (new Event())->setMsBusyStatus($msBusyStatus); + + self::assertEventRendersCorrect($event, $properties); + } } diff --git a/website/docs/component-event.md b/website/docs/component-event.md index 58248d05..fa9edf6d 100644 --- a/website/docs/component-event.md +++ b/website/docs/component-event.md @@ -349,3 +349,15 @@ use Eluceo\iCal\Domain\Enum\EventStatus; $event = new Event(); $event->setStatus(EventStatus::CANCELLED()); ``` + +### MsBusyStatus + +This property represents the status in Microsoft Outlook for freebusy-view. The possible values are `free`, `tentative`, `busy`, `oof`. + +```php +use Eluceo\iCal\Domain\Entity\Event; +use Eluceo\iCal\Domain\Enum\MsBusyStatus; + +$event = new Event(); +$event->setMsBusyStatus(MsBusyStatus::FREE()); +```