mirror of
https://github.com/werkraum-media/events.git
synced 2025-03-24 04:03:48 +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) {
|
||||
return $date;
|
||||
}
|
||||
if (empty($date['repeatCount']) === false) {
|
||||
return $date;
|
||||
}
|
||||
|
||||
$date['repeatUntil'] = $this->getToday()->modify($import->getRepeatUntil())->format('c');
|
||||
$this->logger->info('Interval did not provide repeatUntil.', ['newRepeat' => $date['repeatUntil']]);
|
||||
|
@ -149,7 +152,7 @@ final class DatesFactory
|
|||
$timeZone = new DateTimeZone($date['tz']);
|
||||
$start = new DateTimeImmutable($date['start'], $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);
|
||||
foreach ($period as $day) {
|
||||
|
@ -179,7 +182,7 @@ final class DatesFactory
|
|||
$timeZone = new DateTimeZone($date['tz']);
|
||||
$start = new DateTimeImmutable($date['start'], $timeZone);
|
||||
$end = new DateTimeImmutable($date['end'], $timeZone);
|
||||
$until = new DateTimeImmutable($date['repeatUntil'], $timeZone);
|
||||
$until = $this->createUntil($start, $date, 'weeks');
|
||||
|
||||
foreach ($date['weekdays'] as $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
|
||||
{
|
||||
$today = $this->context->getPropertyFromAspect('date', 'full', new DateTimeImmutable());
|
||||
|
|
|
@ -9,7 +9,10 @@ Nothing
|
|||
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
|
||||
-----
|
|
@ -95,7 +95,7 @@ class DatesFactoryTest extends TestCase
|
|||
}
|
||||
|
||||
#[Test]
|
||||
public function returnsWeeklyWithConfiguredRepeat(): void
|
||||
public function returnsWeeklyWithConfiguredRepeatEndless(): void
|
||||
{
|
||||
$import = self::createStub(Import::class);
|
||||
$import->method('getRepeatUntil')->willReturn('+60 days');
|
||||
|
@ -119,6 +119,78 @@ class DatesFactoryTest extends TestCase
|
|||
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]
|
||||
public function returnsSingleCanceledDate(): void
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ $EM_CONF['events'] = [
|
|||
'author' => 'Dirk Koritnik, Daniel Siepmann',
|
||||
'author_email' => 'koritnik@werkraum-media.de, coding@daniel-siepmann.de',
|
||||
'state' => 'stable',
|
||||
'version' => '5.0.1',
|
||||
'version' => '5.1.0',
|
||||
'constraints' => [
|
||||
'depends' => [
|
||||
'typo3' => '',
|
||||
|
|
Loading…
Add table
Reference in a new issue