44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\NuqloudMasterCalendar\Calendar;
|
|
|
|
use OCA\DAV\CalDAV\CachedSubscriptionProvider;
|
|
use OCA\DAV\CalDAV\CalendarProvider as DavCalendarProvider;
|
|
use OCP\Calendar\ICalendar;
|
|
use OCP\Calendar\ICalendarIsEnabled;
|
|
use OCP\Calendar\ICalendarIsWritable;
|
|
|
|
class SourceCalendarService {
|
|
public const MODE_ALL = 'all';
|
|
public const MODE_EDITABLE = 'editable';
|
|
|
|
public function __construct(
|
|
private DavCalendarProvider $davCalendarProvider,
|
|
private CachedSubscriptionProvider $subscriptionProvider,
|
|
) {
|
|
}
|
|
|
|
/** @return ICalendar[] */
|
|
public function getCalendars(string $principalUri, string $mode): array {
|
|
$calendars = array_merge(
|
|
$this->davCalendarProvider->getCalendars($principalUri),
|
|
$this->subscriptionProvider->getCalendars($principalUri),
|
|
);
|
|
|
|
return array_values(array_filter($calendars, function (ICalendar $calendar) use ($mode): bool {
|
|
if ($calendar instanceof ICalendarIsEnabled && !$calendar->isEnabled()) {
|
|
return false;
|
|
}
|
|
|
|
return $mode !== self::MODE_EDITABLE
|
|
|| ($calendar instanceof ICalendarIsWritable && $calendar->isWritable());
|
|
}));
|
|
}
|
|
|
|
public function identifier(ICalendar $calendar): string {
|
|
return get_class($calendar) . ':' . $calendar->getKey();
|
|
}
|
|
}
|