Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 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\Transparency;
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 ?Transparency $transparency = null;

/**
* @var array<Attendee>
Expand Down Expand Up @@ -329,6 +331,13 @@ public function getStatus(): EventStatus
return $this->status;
}

public function getTransparency(): Transparency
{
assert($this->transparency !== null);

return $this->transparency;
}

public function hasStatus(): bool
{
return $this->status !== null;
Expand All @@ -341,6 +350,19 @@ public function setStatus(EventStatus $status): self
return $this;
}

public function hasTransparency(): bool
{
return $this->transparency !== null;
}

public function setTransparency(Transparency $transparency): self
{
$this->transparency = $transparency;

return $this;
}


public function unsetStatus(): self
{
$this->status = null;
Expand Down
28 changes: 28 additions & 0 deletions src/Domain/Enum/Transparency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the eluceo/iCal package.
*
* (c) 2024 Markus Poerschke <markus@poerschke.nrw>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Eluceo\iCal\Domain\Enum;

final class Transparency
{
private static ?self $opaque = null;
private static ?self $transparent = null;

public static function OPAQUE(): self
{
return self::$opaque ??= new self();
}

public static function TRANSPARENT(): self
{
return self::$transparent ??= new self();
}
}
18 changes: 18 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\Transparency;
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,10 @@ protected function getProperties(Event $event): Generator
yield new Property('STATUS', $this->getEventStatusTextValue($event->getStatus()));
}

if ($event->hasTransparency()) {
yield new Property('TRANSP', $this->getTransparencyTextValue($event->getTransparency()));
}

foreach ($event->getAttachments() as $attachment) {
yield from $this->getAttachmentProperties($attachment);
}
Expand Down Expand Up @@ -278,4 +283,17 @@ 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));
}

public function getTransparencyTextValue(Transparency $transparency): TextValue
{
if ($transparency === Transparency::OPAQUE()) {
return new TextValue('OPAQUE');
}

if ($transparency === Transparency::TRANSPARENT()) {
return new TextValue('TRANSPARENT');
}

throw new UnexpectedValueException(sprintf('The enum %s resulted into an unknown transparency type value that is not yet implemented.', Transparency::class));
}
}
19 changes: 19 additions & 0 deletions tests/Unit/Presentation/Factory/EventFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Eluceo\iCal\Domain\Enum\EventStatus;
use Eluceo\iCal\Domain\Enum\ParticipationStatus;
use Eluceo\iCal\Domain\Enum\RoleType;
use Eluceo\iCal\Domain\Enum\Transparency;
use Eluceo\iCal\Domain\ValueObject\Attachment;
use Eluceo\iCal\Domain\ValueObject\BinaryContent;
use Eluceo\iCal\Domain\ValueObject\Category;
Expand Down Expand Up @@ -550,6 +551,24 @@ public function testEventWithTentativeStatus(): void
]);
}

public function testEventWithTransparentTransparency(): void
{
$event = (new Event())->setTransparency(Transparency::TRANSPARENT());

self::assertEventRendersCorrect($event, [
'TRANSP:TRANSPARENT',
]);
}

public function testEventWithOpaqueTransparency(): void
{
$event = (new Event())->setTransparency(Transparency::OPAQUE());

self::assertEventRendersCorrect($event, [
'TRANSP:OPAQUE',
]);
}

private static function assertEventRendersCorrect(Event $event, array $expected)
{
$resultAsString = (string) (new EventFactory())->createComponent($event);
Expand Down
14 changes: 14 additions & 0 deletions website/docs/component-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,17 @@ use Eluceo\iCal\Domain\Enum\EventStatus;
$event = new Event();
$event->setStatus(EventStatus::CANCELLED());
```


### Transparency

This property defines the transparency of the event, e.g. if it is transparent or opaque. The possible values
are `transparent` and `opaque`.

```php
use Eluceo\iCal\Domain\Entity\Event;
use Eluceo\iCal\Domain\Enum\Transparency;

$event = new Event();
$event->setTransparency(Transparency::TRANSPARENT());
```
2 changes: 1 addition & 1 deletion website/docs/maturity-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ See [RFC 5545 section 3.6.1](https://tools.ietf.org/html/rfc5545#section-3.6.1).
| seq | ✖ |
| status | ✔ |
| summary | ✔ |
| transp | |
| transp | |
| url | ✔ |
| recurid | ✖ |
| rrule | ✖ |
Expand Down