Skip to content

Commit

Permalink
- Add status property in Event
Browse files Browse the repository at this point in the history
- Add merhod property in Event
  • Loading branch information
giuseppenucifora committed Jul 5, 2021
1 parent b65e802 commit f1673ae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
44 changes: 43 additions & 1 deletion src/Domain/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@

class Event
{
const EVENT_STATUS_CONFIRMED = 'CONFIRMED';
const EVENT_STATUS_CANCELLED = 'CANCELLED';
const EVENT_STATUS_TENTATIVE = 'TENTATIVE';

const ALLOWED_EVENT_STATUSES = [self::EVENT_STATUS_CONFIRMED, self::EVENT_STATUS_CANCELLED, self::EVENT_STATUS_TENTATIVE];

const EVENT_METHOD_CONFIRMED = 'PUBLISH';
const EVENT_METHOD_CANCEL = 'CANCEL';

const ALLOWED_EVENT_METHODS = [self::EVENT_METHOD_CONFIRMED, self::EVENT_METHOD_CANCEL];

private UniqueIdentifier $uniqueIdentifier;
private Timestamp $touchedAt;
private ?string $summary = null;
Expand All @@ -29,7 +40,8 @@ class Event
private ?Location $location = null;
private ?Organizer $organizer = null;
private ?Timestamp $lastModified = null;

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

public function getStatus(): ?string
{
assert($this->status !== null);

return $this->status;
}

public function setStatus(?string $status): self
{
assert(in_array($status, self::ALLOWED_EVENT_STATUSES, true));

$this->status = $status;
return $this;
}

public function getMethod(): ?string
{
assert($this->method !== null);

return $this->method;
}

public function setMethod(?string $method): self
{
assert(in_array($method, self::ALLOWED_EVENT_METHODS, true));

$this->method = $method;
return $this;
}

public function getSummary(): string
{
assert($this->summary !== null);
Expand Down
10 changes: 6 additions & 4 deletions src/Presentation/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ public function createComponent(Event $event): Component
*/
protected function getProperties(Event $event): Generator
{
yield new Property('UID', new TextValue((string) $event->getUniqueIdentifier()));
yield new Property('UID', new TextValue((string)$event->getUniqueIdentifier()));
yield new Property('DTSTAMP', new DateTimeValue($event->getTouchedAt()));
yield new Property('STATUS', new TextValue($event->getStatus()));
yield new Property('METHOD', new TextValue($event->getMethod()));

if ($event->hasLastModified()) {
yield new Property('LAST-MODIFIED', new DateTimeValue($event->getLastModified()));
Expand Down Expand Up @@ -111,7 +113,7 @@ protected function getProperties(Event $event): Generator
protected function getComponents(Event $event): Generator
{
yield from array_map(
fn (Alarm $alarm) => $this->alarmFactory->createComponent($alarm),
fn(Alarm $alarm) => $this->alarmFactory->createComponent($alarm),
$event->getAlarms()
);
}
Expand Down Expand Up @@ -141,7 +143,7 @@ private function getOccurrenceProperties(Occurrence $occurrence): Generator
*/
private function getLocationProperties(Event $event): Generator
{
yield new Property('LOCATION', new TextValue((string) $event->getLocation()));
yield new Property('LOCATION', new TextValue((string)$event->getLocation()));

if ($event->getLocation()->hasGeographicalPosition()) {
yield new Property('GEO', new GeoValue($event->getLocation()->getGeographicPosition()));
Expand All @@ -150,7 +152,7 @@ private function getLocationProperties(Event $event): Generator
new AppleLocationGeoValue($event->getLocation()->getGeographicPosition()),
[
new Parameter('VALUE', new TextValue('URI')),
new Parameter('X-ADDRESS', new TextValue((string) $event->getLocation())),
new Parameter('X-ADDRESS', new TextValue((string)$event->getLocation())),
new Parameter('X-APPLE-RADIUS', new IntegerValue(49)),
new Parameter('X-TITLE', new TextValue($event->getLocation()->getTitle())),
]
Expand Down

0 comments on commit f1673ae

Please sign in to comment.