Personal.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
  4. * @copyright Copyright (c) 2019 Janis Köhr <janiskoehr@icloud.com>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author John Molakvoæ <skjnldsv@protonmail.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Theming\Settings;
  27. use OCA\Theming\ITheme;
  28. use OCA\Theming\Service\ThemesService;
  29. use OCA\Theming\ThemingDefaults;
  30. use OCP\App\IAppManager;
  31. use OCP\AppFramework\Http\TemplateResponse;
  32. use OCP\AppFramework\Services\IInitialState;
  33. use OCP\IConfig;
  34. use OCP\Settings\ISettings;
  35. use OCP\Util;
  36. class Personal implements ISettings {
  37. public function __construct(
  38. protected string $appName,
  39. private string $userId,
  40. private IConfig $config,
  41. private ThemesService $themesService,
  42. private IInitialState $initialStateService,
  43. private ThemingDefaults $themingDefaults,
  44. private IAppManager $appManager,
  45. ) {
  46. }
  47. public function getForm(): TemplateResponse {
  48. $enforcedTheme = $this->config->getSystemValueString('enforce_theme', '');
  49. $themes = array_map(function ($theme) {
  50. return [
  51. 'id' => $theme->getId(),
  52. 'type' => $theme->getType(),
  53. 'title' => $theme->getTitle(),
  54. 'enableLabel' => $theme->getEnableLabel(),
  55. 'description' => $theme->getDescription(),
  56. 'enabled' => $this->themesService->isEnabled($theme),
  57. ];
  58. }, $this->themesService->getThemes());
  59. if ($enforcedTheme !== '') {
  60. $themes = array_filter($themes, function ($theme) use ($enforcedTheme) {
  61. return $theme['type'] !== ITheme::TYPE_THEME || $theme['id'] === $enforcedTheme;
  62. });
  63. }
  64. // Get the default app enforced by admin
  65. $forcedDefaultApp = $this->appManager->getDefaultAppForUser(null, false);
  66. $this->initialStateService->provideInitialState('themes', array_values($themes));
  67. $this->initialStateService->provideInitialState('enforceTheme', $enforcedTheme);
  68. $this->initialStateService->provideInitialState('isUserThemingDisabled', $this->themingDefaults->isUserThemingDisabled());
  69. $this->initialStateService->provideInitialState('navigationBar', [
  70. 'userAppOrder' => json_decode($this->config->getUserValue($this->userId, 'core', 'apporder', '[]'), true, flags:JSON_THROW_ON_ERROR),
  71. 'enforcedDefaultApp' => $forcedDefaultApp
  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. }