CalendarProvider.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2021 Anna Larch <anna.larch@gmx.net>
  5. *
  6. * @author Anna Larch <anna.larch@gmx.net>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\CalDAV;
  25. use OCP\Calendar\ICalendarProvider;
  26. use OCP\IConfig;
  27. use OCP\IL10N;
  28. use Psr\Log\LoggerInterface;
  29. class CalendarProvider implements ICalendarProvider {
  30. /** @var CalDavBackend */
  31. private $calDavBackend;
  32. /** @var IL10N */
  33. private $l10n;
  34. /** @var IConfig */
  35. private $config;
  36. /** @var LoggerInterface */
  37. private $logger;
  38. public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config, LoggerInterface $logger) {
  39. $this->calDavBackend = $calDavBackend;
  40. $this->l10n = $l10n;
  41. $this->config = $config;
  42. $this->logger = $logger;
  43. }
  44. public function getCalendars(string $principalUri, array $calendarUris = []): array {
  45. $calendarInfos = [];
  46. if (empty($calendarUris)) {
  47. $calendarInfos = $this->calDavBackend->getCalendarsForUser($principalUri);
  48. } else {
  49. foreach ($calendarUris as $calendarUri) {
  50. $calendarInfos[] = $this->calDavBackend->getCalendarByUri($principalUri, $calendarUri);
  51. }
  52. }
  53. $calendarInfos = array_filter($calendarInfos);
  54. $iCalendars = [];
  55. foreach ($calendarInfos as $calendarInfo) {
  56. $calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  57. $iCalendars[] = new CalendarImpl(
  58. $calendar,
  59. $calendarInfo,
  60. $this->calDavBackend,
  61. );
  62. }
  63. return $iCalendars;
  64. }
  65. }