You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Personal.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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\Accessibility\Settings;
  27. use OCA\Accessibility\AccessibilityProvider;
  28. use OCP\AppFramework\Http\TemplateResponse;
  29. use OCP\AppFramework\Services\IInitialState;
  30. use OCP\IConfig;
  31. use OCP\IL10N;
  32. use OCP\IURLGenerator;
  33. use OCP\IUserSession;
  34. use OCP\Settings\ISettings;
  35. use OCP\Util;
  36. class Personal implements ISettings {
  37. /** @var string */
  38. protected $appName;
  39. /** @var IConfig */
  40. private $config;
  41. /** @var IUserSession */
  42. private $userSession;
  43. /** @var IL10N */
  44. private $l;
  45. /** @var IURLGenerator */
  46. private $urlGenerator;
  47. /** @var AccessibilityProvider */
  48. private $accessibilityProvider;
  49. /** @var IInitialState */
  50. private $initialStateService;
  51. public function __construct(string $appName,
  52. IConfig $config,
  53. IUserSession $userSession,
  54. IL10N $l,
  55. IURLGenerator $urlGenerator,
  56. AccessibilityProvider $accessibilityProvider,
  57. IInitialState $initialStateService) {
  58. $this->appName = $appName;
  59. $this->config = $config;
  60. $this->userSession = $userSession;
  61. $this->l = $l;
  62. $this->urlGenerator = $urlGenerator;
  63. $this->accessibilityProvider = $accessibilityProvider;
  64. $this->initialStateService = $initialStateService;
  65. }
  66. /**
  67. * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
  68. * @since 9.1
  69. */
  70. public function getForm(): TemplateResponse {
  71. Util::addScript('accessibility', 'accessibility');
  72. Util::addStyle('accessibility', 'style');
  73. $availableConfig = [
  74. 'themes' => $this->accessibilityProvider->getThemes(),
  75. 'fonts' => $this->accessibilityProvider->getFonts(),
  76. 'highcontrast' => $this->accessibilityProvider->getHighContrast()
  77. ];
  78. $userConfig = [
  79. 'highcontrast' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'highcontrast', false),
  80. 'theme' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false),
  81. 'font' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false)
  82. ];
  83. $this->initialStateService->provideInitialState('available-config', $availableConfig);
  84. $this->initialStateService->provideInitialState('user-config', $userConfig);
  85. return new TemplateResponse($this->appName, 'settings-personal');
  86. }
  87. /**
  88. * @return string the section ID, e.g. 'sharing'
  89. * @since 9.1
  90. */
  91. public function getSection(): string {
  92. return $this->appName;
  93. }
  94. /**
  95. * @return int whether the form should be rather on the top or bottom of
  96. * the admin section. The forms are arranged in ascending order of the
  97. * priority values. It is required to return a value between 0 and 100.
  98. *
  99. * E.g.: 70
  100. * @since 9.1
  101. */
  102. public function getPriority(): int {
  103. return 40;
  104. }
  105. }