Release: CalDAV sync bundle hardening and LMW sync
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mummert\CalDavSyncBundle\Config;
|
||||
|
||||
final readonly class CalendarSyncConfig
|
||||
{
|
||||
/**
|
||||
* @param list<string> $selectedCalendarUrls
|
||||
*/
|
||||
public function __construct(
|
||||
public int $calendarId,
|
||||
public string $caldavUrl,
|
||||
public string $caldavUsername,
|
||||
public string $caldavPassword,
|
||||
public int $caldavAuthorId,
|
||||
public string $caldavTimezone,
|
||||
public array $selectedCalendarUrls,
|
||||
) {
|
||||
}
|
||||
|
||||
public function timezoneOrDefault(): string
|
||||
{
|
||||
return '' !== trim($this->caldavTimezone) ? $this->caldavTimezone : 'UTC';
|
||||
}
|
||||
|
||||
public function hasMultipleRemoteCalendars(): bool
|
||||
{
|
||||
return count($this->selectedCalendarUrls) > 1;
|
||||
}
|
||||
|
||||
public function shouldManageEventForThisRemoteCalendar(string $eventCalendarUrl): bool
|
||||
{
|
||||
$normalizedEventUrl = trim($eventCalendarUrl);
|
||||
if ('' === $normalizedEventUrl) {
|
||||
return !$this->hasMultipleRemoteCalendars();
|
||||
}
|
||||
|
||||
return $normalizedEventUrl === $this->caldavUrl;
|
||||
}
|
||||
|
||||
public function resolveTargetCalendarForLocalEvent(string $eventCalendarUrl): ?string
|
||||
{
|
||||
$normalizedEventUrl = trim($eventCalendarUrl);
|
||||
if ('' !== $normalizedEventUrl) {
|
||||
return $normalizedEventUrl;
|
||||
}
|
||||
|
||||
if ([] === $this->selectedCalendarUrls) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->selectedCalendarUrls[0];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user