diff options
Diffstat (limited to 'lib/private/Calendar/Manager.php')
-rw-r--r-- | lib/private/Calendar/Manager.php | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/lib/private/Calendar/Manager.php b/lib/private/Calendar/Manager.php index ab22c3ba7b8..30ee60e4943 100644 --- a/lib/private/Calendar/Manager.php +++ b/lib/private/Calendar/Manager.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright 2017, Georg Ehrke <oc.list@georgehrke.com> * @@ -23,9 +26,13 @@ */ namespace OC\Calendar; +use OC\AppFramework\Bootstrap\Coordinator; use OCP\Calendar\ICalendar; +use OCP\Calendar\ICalendarProvider; +use OCP\Calendar\ICalendarQuery; +use OCP\Calendar\IManager; -class Manager implements \OCP\Calendar\IManager { +class Manager implements IManager { /** * @var ICalendar[] holds all registered calendars @@ -37,6 +44,13 @@ class Manager implements \OCP\Calendar\IManager { */ private $calendarLoaders = []; + /** @var Coordinator */ + private $coordinator; + + public function __construct(Coordinator $coordinator) { + $this->coordinator = $coordinator; + } + /** * This function is used to search and find objects within the user's calendars. * In case $pattern is empty all events/journals/todos will be returned. @@ -137,4 +151,38 @@ class Manager implements \OCP\Calendar\IManager { } $this->calendarLoaders = []; } + + public function searchForPrincipal(ICalendarQuery $query): array { + $context = $this->coordinator->getRegistrationContext(); + if ($context === null) { + return []; + } + + /** @var CalendarQuery $query */ + $calendars = array_merge(...array_map(static function (ICalendarProvider $p) use ($query) { + return $p->getCalendars($query->getPrincipalUri(), $query->getCalendarUris()); + }, $context->getCalendarProviders())); + + $results = []; + /** @var ICalendar $calendar */ + foreach ($calendars as $calendar) { + $r = $calendar->search( + $query->getSearchPattern() ?? '', + $query->getSearchProperties(), + $query->getOptions(), + $query->getLimit(), + $query->getOffset() + ); + + foreach ($r as $o) { + $o['calendar-key'] = $calendar->getKey(); + $results[] = $o; + } + } + return $results; + } + + public function newQuery(string $principalUri): ICalendarQuery { + return new CalendarQuery($principalUri); + } } |