57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?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];
|
|
}
|
|
}
|