1
0

Personal.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Theming\Settings;
  7. use OCA\Theming\ITheme;
  8. use OCA\Theming\Service\BackgroundService;
  9. use OCA\Theming\Service\ThemesService;
  10. use OCA\Theming\ThemingDefaults;
  11. use OCP\AppFramework\Http\TemplateResponse;
  12. use OCP\AppFramework\Services\IInitialState;
  13. use OCP\IConfig;
  14. use OCP\INavigationManager;
  15. use OCP\Settings\ISettings;
  16. use OCP\Util;
  17. class Personal implements ISettings {
  18. public function __construct(
  19. protected string $appName,
  20. private string $userId,
  21. private IConfig $config,
  22. private ThemesService $themesService,
  23. private IInitialState $initialStateService,
  24. private ThemingDefaults $themingDefaults,
  25. private INavigationManager $navigationManager,
  26. ) {
  27. }
  28. public function getForm(): TemplateResponse {
  29. $enforcedTheme = $this->config->getSystemValueString('enforce_theme', '');
  30. $themes = array_map(function ($theme) {
  31. return [
  32. 'id' => $theme->getId(),
  33. 'type' => $theme->getType(),
  34. 'title' => $theme->getTitle(),
  35. 'enableLabel' => $theme->getEnableLabel(),
  36. 'description' => $theme->getDescription(),
  37. 'enabled' => $this->themesService->isEnabled($theme),
  38. ];
  39. }, $this->themesService->getThemes());
  40. if ($enforcedTheme !== '') {
  41. $themes = array_filter($themes, function ($theme) use ($enforcedTheme) {
  42. return $theme['type'] !== ITheme::TYPE_THEME || $theme['id'] === $enforcedTheme;
  43. });
  44. }
  45. // Get the default entry enforced by admin
  46. $forcedDefaultEntry = $this->navigationManager->getDefaultEntryIdForUser(null, false);
  47. /** List of all shipped backgrounds */
  48. $this->initialStateService->provideInitialState('shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS);
  49. /**
  50. * Admin theming
  51. */
  52. $this->initialStateService->provideInitialState('themingDefaults', [
  53. /** URL of admin configured background image */
  54. 'backgroundImage' => $this->themingDefaults->getBackground(),
  55. /** `backgroundColor` if disabled, mime type if defined and empty by default */
  56. 'backgroundMime' => $this->config->getAppValue('theming', 'backgroundMime', ''),
  57. /** Admin configured background color */
  58. 'backgroundColor' => $this->themingDefaults->getDefaultColorBackground(),
  59. /** Admin configured primary color */
  60. 'primaryColor' => $this->themingDefaults->getDefaultColorPrimary(),
  61. /** Nextcloud default background image */
  62. 'defaultShippedBackground' => BackgroundService::DEFAULT_BACKGROUND_IMAGE,
  63. ]);
  64. $this->initialStateService->provideInitialState('userBackgroundImage', $this->config->getUserValue($this->userId, 'theming', 'background_image', BackgroundService::BACKGROUND_DEFAULT));
  65. $this->initialStateService->provideInitialState('themes', array_values($themes));
  66. $this->initialStateService->provideInitialState('enforceTheme', $enforcedTheme);
  67. $this->initialStateService->provideInitialState('isUserThemingDisabled', $this->themingDefaults->isUserThemingDisabled());
  68. $this->initialStateService->provideInitialState('enableBlurFilter', $this->config->getUserValue($this->userId, 'theming', 'force_enable_blur_filter', ''));
  69. $this->initialStateService->provideInitialState('navigationBar', [
  70. 'userAppOrder' => json_decode($this->config->getUserValue($this->userId, 'core', 'apporder', '[]'), true, flags:JSON_THROW_ON_ERROR),
  71. 'enforcedDefaultApp' => $forcedDefaultEntry
  72. ]);
  73. Util::addScript($this->appName, 'personal-theming');
  74. return new TemplateResponse($this->appName, 'settings-personal');
  75. }
  76. /**
  77. * @return string the section ID, e.g. 'sharing'
  78. * @since 9.1
  79. */
  80. public function getSection(): string {
  81. return $this->appName;
  82. }
  83. /**
  84. * @return int whether the form should be rather on the top or bottom of
  85. * the admin section. The forms are arranged in ascending order of the
  86. * priority values. It is required to return a value between 0 and 100.
  87. *
  88. * E.g.: 70
  89. * @since 9.1
  90. */
  91. public function getPriority(): int {
  92. return 40;
  93. }
  94. }