mirror of
https://github.com/werkraum-media/events.git
synced 2025-03-26 15:23:47 +01:00
Support destination.one repeatCount
property
This provides info on how often a repeatable event should be repeated. E.g. `1` = exactly once, so no actual repeat. Relates: #11666
This commit is contained in:
parent
3fae8867a4
commit
d1f8b253e4
4 changed files with 98 additions and 5 deletions
Classes/Service/DestinationDataImportService
Documentation/Changelog
Tests/Unit/Service/DestinationDataImportService
ext_emconf.php
|
@ -131,6 +131,9 @@ final class DatesFactory
|
||||||
if (empty($date['repeatUntil']) === false) {
|
if (empty($date['repeatUntil']) === false) {
|
||||||
return $date;
|
return $date;
|
||||||
}
|
}
|
||||||
|
if (empty($date['repeatCount']) === false) {
|
||||||
|
return $date;
|
||||||
|
}
|
||||||
|
|
||||||
$date['repeatUntil'] = $this->getToday()->modify($import->getRepeatUntil())->format('c');
|
$date['repeatUntil'] = $this->getToday()->modify($import->getRepeatUntil())->format('c');
|
||||||
$this->logger->info('Interval did not provide repeatUntil.', ['newRepeat' => $date['repeatUntil']]);
|
$this->logger->info('Interval did not provide repeatUntil.', ['newRepeat' => $date['repeatUntil']]);
|
||||||
|
@ -149,7 +152,7 @@ final class DatesFactory
|
||||||
$timeZone = new DateTimeZone($date['tz']);
|
$timeZone = new DateTimeZone($date['tz']);
|
||||||
$start = new DateTimeImmutable($date['start'], $timeZone);
|
$start = new DateTimeImmutable($date['start'], $timeZone);
|
||||||
$end = new DateTimeImmutable($date['end'], $timeZone);
|
$end = new DateTimeImmutable($date['end'], $timeZone);
|
||||||
$until = new DateTimeImmutable($date['repeatUntil'], $timeZone);
|
$until = $this->createUntil($start, $date, 'days');
|
||||||
|
|
||||||
$period = new DatePeriod($start, new DateInterval('P1D'), $until);
|
$period = new DatePeriod($start, new DateInterval('P1D'), $until);
|
||||||
foreach ($period as $day) {
|
foreach ($period as $day) {
|
||||||
|
@ -179,7 +182,7 @@ final class DatesFactory
|
||||||
$timeZone = new DateTimeZone($date['tz']);
|
$timeZone = new DateTimeZone($date['tz']);
|
||||||
$start = new DateTimeImmutable($date['start'], $timeZone);
|
$start = new DateTimeImmutable($date['start'], $timeZone);
|
||||||
$end = new DateTimeImmutable($date['end'], $timeZone);
|
$end = new DateTimeImmutable($date['end'], $timeZone);
|
||||||
$until = new DateTimeImmutable($date['repeatUntil'], $timeZone);
|
$until = $this->createUntil($start, $date, 'weeks');
|
||||||
|
|
||||||
foreach ($date['weekdays'] as $day) {
|
foreach ($date['weekdays'] as $day) {
|
||||||
$dateToUse = $start->modify($day);
|
$dateToUse = $start->modify($day);
|
||||||
|
@ -216,6 +219,21 @@ final class DatesFactory
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $repeatCountUnit E.g. weeks or days
|
||||||
|
*/
|
||||||
|
private function createUntil(
|
||||||
|
DateTimeImmutable $start,
|
||||||
|
array $date,
|
||||||
|
string $repeatCountUnit,
|
||||||
|
): DateTimeImmutable {
|
||||||
|
if (array_key_exists('repeatUntil', $date)) {
|
||||||
|
return new DateTimeImmutable($date['repeatUntil'], $start->getTimezone());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $start->modify('+' . ((int)$date['repeatCount']) . ' ' . $repeatCountUnit);
|
||||||
|
}
|
||||||
|
|
||||||
private function getToday(): DateTimeImmutable
|
private function getToday(): DateTimeImmutable
|
||||||
{
|
{
|
||||||
$today = $this->context->getPropertyFromAspect('date', 'full', new DateTimeImmutable());
|
$today = $this->context->getPropertyFromAspect('date', 'full', new DateTimeImmutable());
|
||||||
|
|
|
@ -9,7 +9,10 @@ Nothing
|
||||||
Features
|
Features
|
||||||
--------
|
--------
|
||||||
|
|
||||||
Nothing
|
* Support destination.one `repeatCount` property.
|
||||||
|
|
||||||
|
This provides info on how often a repeatable event should be repeated.
|
||||||
|
E.g. `1` = exactly once, so no actual repeat.
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
-----
|
-----
|
|
@ -95,7 +95,7 @@ class DatesFactoryTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function returnsWeeklyWithConfiguredRepeat(): void
|
public function returnsWeeklyWithConfiguredRepeatEndless(): void
|
||||||
{
|
{
|
||||||
$import = self::createStub(Import::class);
|
$import = self::createStub(Import::class);
|
||||||
$import->method('getRepeatUntil')->willReturn('+60 days');
|
$import->method('getRepeatUntil')->willReturn('+60 days');
|
||||||
|
@ -119,6 +119,78 @@ class DatesFactoryTest extends TestCase
|
||||||
self::assertCount(16, $result);
|
self::assertCount(16, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Test]
|
||||||
|
public function returnsWeeklyWithConfiguredRepeatCountOfOne(): void
|
||||||
|
{
|
||||||
|
$import = self::createStub(Import::class);
|
||||||
|
$import->method('getRepeatUntil')->willReturn('+60 days');
|
||||||
|
$subject = $this->createTestSubject('2023-01-01T13:17:24 Europe/Berlin');
|
||||||
|
|
||||||
|
$result = $subject->createDates($import, [[
|
||||||
|
'weekdays' => [
|
||||||
|
'Monday',
|
||||||
|
],
|
||||||
|
'start' => '2023-01-06T14:00:00+01:00',
|
||||||
|
'end' => '2023-01-06T15:00:00+01:00',
|
||||||
|
'tz' => 'Europe/Berlin',
|
||||||
|
'freq' => 'Weekly',
|
||||||
|
'interval' => 1,
|
||||||
|
'repeatCount' => 1,
|
||||||
|
]], false);
|
||||||
|
|
||||||
|
self::assertInstanceOf(Generator::class, $result);
|
||||||
|
$result = iterator_to_array($result);
|
||||||
|
|
||||||
|
self::assertCount(1, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Test]
|
||||||
|
public function returnsWeeklyWithConfiguredRepeatCountOfThree(): void
|
||||||
|
{
|
||||||
|
$import = self::createStub(Import::class);
|
||||||
|
$import->method('getRepeatUntil')->willReturn('+60 days');
|
||||||
|
$subject = $this->createTestSubject('2023-01-01T13:17:24 Europe/Berlin');
|
||||||
|
|
||||||
|
$result = $subject->createDates($import, [[
|
||||||
|
'weekdays' => [
|
||||||
|
'Monday',
|
||||||
|
],
|
||||||
|
'start' => '2023-01-06T14:00:00+01:00',
|
||||||
|
'end' => '2023-01-06T15:00:00+01:00',
|
||||||
|
'tz' => 'Europe/Berlin',
|
||||||
|
'freq' => 'Weekly',
|
||||||
|
'interval' => 1,
|
||||||
|
'repeatCount' => 3,
|
||||||
|
]], false);
|
||||||
|
|
||||||
|
self::assertInstanceOf(Generator::class, $result);
|
||||||
|
$result = iterator_to_array($result);
|
||||||
|
|
||||||
|
self::assertCount(3, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Test]
|
||||||
|
public function returnsDailyWithConfiguredRepeatCount(): void
|
||||||
|
{
|
||||||
|
$import = self::createStub(Import::class);
|
||||||
|
$import->method('getRepeatUntil')->willReturn('+60 days');
|
||||||
|
$subject = $this->createTestSubject('2023-01-01T13:17:24 Europe/Berlin');
|
||||||
|
|
||||||
|
$result = $subject->createDates($import, [[
|
||||||
|
'start' => '2023-01-06T14:00:00+01:00',
|
||||||
|
'end' => '2023-01-06T15:00:00+01:00',
|
||||||
|
'tz' => 'Europe/Berlin',
|
||||||
|
'freq' => 'Daily',
|
||||||
|
'interval' => 1,
|
||||||
|
'repeatCount' => 1,
|
||||||
|
]], false);
|
||||||
|
|
||||||
|
self::assertInstanceOf(Generator::class, $result);
|
||||||
|
$result = iterator_to_array($result);
|
||||||
|
|
||||||
|
self::assertCount(1, $result);
|
||||||
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function returnsSingleCanceledDate(): void
|
public function returnsSingleCanceledDate(): void
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,7 +9,7 @@ $EM_CONF['events'] = [
|
||||||
'author' => 'Dirk Koritnik, Daniel Siepmann',
|
'author' => 'Dirk Koritnik, Daniel Siepmann',
|
||||||
'author_email' => 'koritnik@werkraum-media.de, coding@daniel-siepmann.de',
|
'author_email' => 'koritnik@werkraum-media.de, coding@daniel-siepmann.de',
|
||||||
'state' => 'stable',
|
'state' => 'stable',
|
||||||
'version' => '5.0.1',
|
'version' => '5.1.0',
|
||||||
'constraints' => [
|
'constraints' => [
|
||||||
'depends' => [
|
'depends' => [
|
||||||
'typo3' => '',
|
'typo3' => '',
|
||||||
|
|
Loading…
Add table
Reference in a new issue