CalDAVSettings.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\Settings;
  7. use OCA\DAV\AppInfo\Application;
  8. use OCP\App\IAppManager;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\AppFramework\Services\IInitialState;
  11. use OCP\IConfig;
  12. use OCP\IURLGenerator;
  13. use OCP\Settings\IDelegatedSettings;
  14. class CalDAVSettings implements IDelegatedSettings {
  15. /** @var IConfig */
  16. private $config;
  17. /** @var IInitialState */
  18. private $initialState;
  19. private IURLGenerator $urlGenerator;
  20. private IAppManager $appManager;
  21. private const defaults = [
  22. 'sendInvitations' => 'yes',
  23. 'generateBirthdayCalendar' => 'yes',
  24. 'sendEventReminders' => 'yes',
  25. 'sendEventRemindersToSharedUsers' => 'yes',
  26. 'sendEventRemindersPush' => 'yes',
  27. ];
  28. /**
  29. * CalDAVSettings constructor.
  30. *
  31. * @param IConfig $config
  32. * @param IInitialState $initialState
  33. */
  34. public function __construct(IConfig $config, IInitialState $initialState, IURLGenerator $urlGenerator, IAppManager $appManager) {
  35. $this->config = $config;
  36. $this->initialState = $initialState;
  37. $this->urlGenerator = $urlGenerator;
  38. $this->appManager = $appManager;
  39. }
  40. public function getForm(): TemplateResponse {
  41. $this->initialState->provideInitialState('userSyncCalendarsDocUrl', $this->urlGenerator->linkToDocs('user-sync-calendars'));
  42. foreach (self::defaults as $key => $default) {
  43. $value = $this->config->getAppValue(Application::APP_ID, $key, $default);
  44. $this->initialState->provideInitialState($key, $value === 'yes');
  45. }
  46. return new TemplateResponse(Application::APP_ID, 'settings-admin-caldav');
  47. }
  48. public function getSection(): ?string {
  49. if (!$this->appManager->isBackendRequired(IAppManager::BACKEND_CALDAV)) {
  50. return null;
  51. }
  52. return 'groupware';
  53. }
  54. /**
  55. * @return int
  56. */
  57. public function getPriority() {
  58. return 10;
  59. }
  60. public function getName(): ?string {
  61. return null; // Only setting in this section
  62. }
  63. public function getAuthorizedAppConfig(): array {
  64. return [
  65. 'dav' => ['/(' . implode('|', array_keys(self::defaults)) . ')/']
  66. ];
  67. }
  68. }