Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status and method in calendar event #300

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Event LAST-MODIFIED property [#298](https://github.com/markuspoerschke/iCal/pull/298)
- Event STATUS and METHOD property [#300](https://github.com/markuspoerschke/iCal/pull/300)

## [2.2.0] - 2021-05-03

Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 38 additions & 1 deletion src/Domain/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Eluceo\iCal\Domain\Entity;

use Eluceo\iCal\Domain\Enum\MethodType;
use Eluceo\iCal\Domain\Enum\StatusType;
use Eluceo\iCal\Domain\ValueObject\Alarm;
use Eluceo\iCal\Domain\ValueObject\Attachment;
use Eluceo\iCal\Domain\ValueObject\Location;
Expand All @@ -29,7 +31,8 @@ class Event
private ?Location $location = null;
private ?Organizer $organizer = null;
private ?Timestamp $lastModified = null;

private ?StatusType $status = null;
private ?MethodType $method = null;
/**
* @var array<Alarm>
*/
Expand Down Expand Up @@ -63,6 +66,40 @@ public function touch(?Timestamp $dateTime = null): self
return $this;
}

public function getStatus(): ?StatusType
{
return $this->status;
}

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

public function setStatus(?StatusType $status): Event
{
$this->status = $status;

return $this;
}

public function getMethod(): ?MethodType
{
return $this->method;
}

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

public function setMethod(?MethodType $method): Event
{
$this->method = $method;

return $this;
}

public function getSummary(): string
{
assert($this->summary !== null);
Expand Down
42 changes: 42 additions & 0 deletions src/Domain/Enum/MethodType.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) 2021 Markus Poerschke <[email protected]>
*
* 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 MethodType
giuseppenucifora marked this conversation as resolved.
Show resolved Hide resolved
{
private static ?self $publish = null;
private static ?self $cancel = null;

private string $method;

public function __construct(string $method)
{
assert(!empty($method), 'Method cannot be empty');

$this->method = $method;
}

public static function PUBLISH(): self
{
return self::$publish = self::$publish ?? new MethodType('PUBLISH');
}

public static function CANCELLED(): self
{
return self::$cancel = self::$cancel ?? new MethodType('CANCEL');
}

public function __toString()
{
return $this->method;
}
}
48 changes: 48 additions & 0 deletions src/Domain/Enum/StatusType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of the eluceo/iCal package.
*
* (c) 2021 Markus Poerschke <[email protected]>
*
* 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 StatusType
giuseppenucifora marked this conversation as resolved.
Show resolved Hide resolved
{
private static ?self $confirmed = null;
private static ?self $cancelled = null;
private static ?self $tentative = null;

private string $status;

public function __construct(string $status)
{
assert(!empty($status), 'Status cannot be empty');

$this->status = $status;
}

public static function CONFIRMED(): self
{
return self::$confirmed = self::$confirmed ?? new StatusType('CONFIRMED');
}

public static function CANCELLED(): self
{
return self::$cancelled = self::$cancelled ?? new StatusType('CANCELLED');
}

public static function TENTATIVE(): self
{
return self::$tentative = self::$tentative ?? new StatusType('TENTATIVE');
}

public function __toString()
{
return $this->status;
}
}
8 changes: 8 additions & 0 deletions src/Presentation/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ protected function getProperties(Event $event): Generator
yield new Property('UID', new TextValue((string) $event->getUniqueIdentifier()));
yield new Property('DTSTAMP', new DateTimeValue($event->getTouchedAt()));

if ($event->hasStatus()) {
yield new Property('STATUS', new TextValue((string) $event->getStatus()));
}

if ($event->hasMethod()) {
yield new Property('METHOD', new TextValue((string) $event->getMethod()));
}

if ($event->hasLastModified()) {
yield new Property('LAST-MODIFIED', new DateTimeValue($event->getLastModified()));
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/Presentation/Factory/EventFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use DateTimeImmutable;
use DateTimeZone;
use Eluceo\iCal\Domain\Entity\Event;
use Eluceo\iCal\Domain\Enum\MethodType;
use Eluceo\iCal\Domain\Enum\StatusType;
use Eluceo\iCal\Domain\ValueObject\Attachment;
use Eluceo\iCal\Domain\ValueObject\BinaryContent;
use Eluceo\iCal\Domain\ValueObject\Date;
Expand Down Expand Up @@ -178,6 +180,26 @@ public function testOrganizer()
]);
}

public function testStatus()
{
$event = (new Event())
->setStatus(StatusType::CONFIRMED());

self::assertEventRendersCorrect($event, [
'STATUS:CONFIRMED',
]);
}

public function testMethod()
{
$event = (new Event())
->setMethod(MethodType::PUBLISH());

self::assertEventRendersCorrect($event, [
'METHOD:PUBLISH',
]);
}

private static function assertEventRendersCorrect(Event $event, array $expected)
{
$resultAsString = (string) (new EventFactory())->createComponent($event);
Expand Down