Skip to content

Commit

Permalink
Merge pull request #29533 from nextcloud/enhancement/get-calendars-fo…
Browse files Browse the repository at this point in the history
…r-principal-api

Add IManager::getCalendarsForPrincipal API
  • Loading branch information
ChristophWurst authored Nov 4, 2021
2 parents b453fea + 3ef6a09 commit 18e6288
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
17 changes: 12 additions & 5 deletions lib/private/Calendar/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,14 @@ private function loadCalendars() {
$this->calendarLoaders = [];
}

public function searchForPrincipal(ICalendarQuery $query): array {
public function getCalendarsForPrincipal(string $principalUri, array $calendarUris = []): array {
$context = $this->coordinator->getRegistrationContext();
if ($context === null) {
return [];
}

/** @var CalendarQuery $query */
$calendars = array_merge(
...array_map(function ($registration) use ($query) {
return array_merge(
...array_map(function ($registration) use ($principalUri, $calendarUris) {
try {
/** @var ICalendarProvider $provider */
$provider = $this->container->get($registration->getService());
Expand All @@ -186,9 +185,17 @@ public function searchForPrincipal(ICalendarQuery $query): array {
return [];
}

return $provider->getCalendars($query->getPrincipalUri(), $query->getCalendarUris());
return $provider->getCalendars($principalUri, $calendarUris);
}, $context->getCalendarProviders())
);
}

public function searchForPrincipal(ICalendarQuery $query): array {
/** @var CalendarQuery $query */
$calendars = $this->getCalendarsForPrincipal(
$query->getPrincipalUri(),
$query->getCalendarUris(),
);

$results = [];
/** @var ICalendar $calendar */
Expand Down
4 changes: 2 additions & 2 deletions lib/public/Calendar/ICalendarProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
interface ICalendarProvider {

/**
* @param string $principalUri
* @param string[] $calendarUris
* @param string $principalUri URI of the principal
* @param string[] $calendarUris optionally specify which calendars to load, or all if this array is empty
* @return ICalendar[]
* @since 23.0.0
*/
Expand Down
11 changes: 10 additions & 1 deletion lib/public/Calendar/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function register(\Closure $callable);
/**
* @return ICalendar[]
* @since 13.0.0
* @deprecated 23.0.0
* @deprecated 23.0.0 use \OCP\Calendar\IManager::getCalendarsForPrincipal
*/
public function getCalendars();

Expand All @@ -131,6 +131,15 @@ public function getCalendars();
*/
public function clear();

/**
* @param string $principalUri URI of the principal
* @param string[] $calendarUris optionally specify which calendars to load, or all if this array is empty
*
* @return ICalendar[]
* @since 23.0.0
*/
public function getCalendarsForPrincipal(string $principalUri, array $calendarUris = []): array;

/**
* Query a principals calendar(s)
*
Expand Down

0 comments on commit 18e6288

Please sign in to comment.