Skip to content

Commit

Permalink
Split up ICalEvent and add RRULE
Browse files Browse the repository at this point in the history
The methodes of ICalEvent regarding the date options / configuration
are now split into an seperate interface.
In addition to that the getRRule() methode was added, which returns
the RRULE property as an key-value array of recur-rule-parts.
  • Loading branch information
okmiim committed Dec 19, 2020
1 parent b1d09d7 commit 58639a1
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 69 deletions.
8 changes: 8 additions & 0 deletions Classes/Ical/DissectEventAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,12 @@ public function getState(): string

return ConfigurationInterface::STATE_DEFAULT;
}

/**
* {@inheritdoc}
*/
public function getRRule(): array
{
return $this->event->getRRule() ?? [];
}
}
89 changes: 89 additions & 0 deletions Classes/Ical/EventConfigurationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace HDNET\Calendarize\Ical;

/**
* Provides the methods to hydrate a Configuration object.
* Used to create a Configuration based on an iCalendar VEVENT.
*
* Interface EventConfigurationInterface
*/
interface EventConfigurationInterface
{
/**
* Value for starTime if the event is allDay.
*/
public const ALLDAY_START_TIME = 0;
/**
* Value for endTime if the event is allDay.
*/
public const ALLDAY_END_TIME = 0;

/**
* Get the start date.
* The date is converted to the local timezone and set to the beginning of the day.
*
* @return \DateTime|null
*/
public function getStartDate(): ?\DateTime;

/**
* Get the inclusive end date.
* The date is converted to the local timezone and set to the beginning of the day.
*
* @return \DateTime|null
*/
public function getEndDate(): ?\DateTime;

/**
* Get start time.
* The time is calculated in the local timezone.
*
* @return int
*/
public function getStartTime(): int;

/**
* Get end time.
* The time is calculated in the local timezone.
*
* @return int
*/
public function getEndTime(): int;

/**
* Get allDay.
*
* The "VEVENT" is also the calendar component used to specify an
* anniversary or daily reminder within a calendar. These events
* have a DATE value type for the "DTSTART" property instead of the
* default value type of DATE-TIME. If such a "VEVENT" has a "DTEND"
* property, it MUST be specified as a DATE value also.
*
* @return bool
*/
public function isAllDay(): bool;

/**
* Get openEndTime.
*
* @return bool
*/
public function isOpenEndTime(): bool;

/**
* Get state.
*
* @return string
*/
public function getState(): string;

/**
* Get repeating rules.
*
* @return array
*/
public function getRRule(): array;
}
70 changes: 1 addition & 69 deletions Classes/Ical/ICalEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@

namespace HDNET\Calendarize\Ical;

interface ICalEvent
interface ICalEvent extends EventConfigurationInterface
{
/**
* Value for starTime if the event is allDay.
*/
const ALLDAY_START_TIME = 0;
/**
* Value for endTime if the event is allDay.
*/
const ALLDAY_END_TIME = 0;

/**
* Returns event data as key value array.
*
Expand Down Expand Up @@ -56,63 +47,4 @@ public function getLocation(): ?string;
* @return string|null
*/
public function getOrganizer(): ?string;

/**
* Get the start date.
* The date is converted to the local timezone and set to the beginning of the day.
*
* @return \DateTime|null
*/
public function getStartDate(): ?\DateTime;

/**
* Get the inclusive end date.
* The date is converted to the local timezone and set to the beginning of the day.
*
* @return \DateTime|null
*/
public function getEndDate(): ?\DateTime;

/**
* Get start time.
* The time is calculated in the local timezone.
*
* @return int
*/
public function getStartTime(): int;

/**
* Get end time.
* The time is calculated in the local timezone.
*
* @return int
*/
public function getEndTime(): int;

/**
* Get allDay.
*
* The "VEVENT" is also the calendar component used to specify an
* anniversary or daily reminder within a calendar. These events
* have a DATE value type for the "DTSTART" property instead of the
* default value type of DATE-TIME. If such a "VEVENT" has a "DTEND"
* property, it MUST be specified as a DATE value also.
*
* @return bool
*/
public function isAllDay(): bool;

/**
* Get openEndTime.
*
* @return bool
*/
public function isOpenEndTime(): bool;

/**
* Get state.
*
* @return string
*/
public function getState(): string;
}
16 changes: 16 additions & 0 deletions Classes/Ical/VObjectEventAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,20 @@ public function getState(): string

return ConfigurationInterface::STATE_DEFAULT;
}

/**
* {@inheritdoc}
*/
public function getRRule(): array
{
if (!isset($this->event->RRULE)) {
return [];
}
$rrule = $this->event->RRULE->getValue();
if (\is_string($rrule)) {
$rrule = \Sabre\VObject\Property\ICalendar\Recur::stringToArray($rrule);
}

return $rrule;
}
}
26 changes: 26 additions & 0 deletions Tests/Unit/Ical/ICalEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,30 @@ public function testDuration()
self::assertEquals(69240, $event->getEndTime());
self::assertFalse($event->isAllDay());
}

public function testRRule()
{
$input = 'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CalendarizeTest
BEGIN:VEVENT
UID:64843636-21d6-44e3-8f8f-6174845e2342@example.com
DTSTAMP:20050404T112124Z
DTSTART:20050404T195534Z
RRULE:FREQ=DAILY;INTERVAL=1;COUNT=45
END:VEVENT
END:VCALENDAR
';
$event = $this->getEvent($input);
$rrule = $event->getRRule();

self::assertArrayHasKey('FREQ', $rrule);
self::assertEqualsIgnoringCase('DAILY', $rrule['FREQ']);

self::assertArrayHasKey('INTERVAL', $rrule);
self::assertEqualsIgnoringCase('1', $rrule['INTERVAL']);

self::assertArrayHasKey('COUNT', $rrule);
self::assertEqualsIgnoringCase('45', $rrule['COUNT']);
}
}

0 comments on commit 58639a1

Please sign in to comment.