Skip to content

Commit

Permalink
restore lost event property X-MICROSOFT-CDO-BUSYSTATUS
Browse files Browse the repository at this point in the history
  • Loading branch information
rohm1 committed Sep 27, 2024
1 parent d666201 commit eaaad97
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/Domain/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,7 @@ class Event
private ?Organizer $organizer = null;
private ?Timestamp $lastModified = null;
private ?EventStatus $status = null;
private ?MsBusyStatus $msBusyStatus = null;

/**
* @var array<Attendee>
Expand Down Expand Up @@ -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;
}
}
42 changes: 42 additions & 0 deletions src/Domain/Enum/MsBusyStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the eluceo/iCal package.
*
* (c) 2024 Markus Poerschke <[email protected]>
*
* 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();
}
}
27 changes: 27 additions & 0 deletions src/Presentation/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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));
}
}
10 changes: 9 additions & 1 deletion tests/Integration/EventsGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
};
Expand All @@ -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',
];
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/Presentation/Factory/EventFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions website/docs/component-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());
```

0 comments on commit eaaad97

Please sign in to comment.