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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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) <skjnldsv@protonmail.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Accessibility\Settings;
  26. use OCA\Accessibility\AccessibilityProvider;
  27. use OCP\AppFramework\Http\TemplateResponse;
  28. use OCP\IConfig;
  29. use OCP\IInitialStateService;
  30. use OCP\IL10N;
  31. use OCP\IURLGenerator;
  32. use OCP\IUserSession;
  33. use OCP\Settings\ISettings;
  34. use OCP\Util;
  35. class Personal implements ISettings {
  36. /** @var string */
  37. protected $appName;
  38. /** @var IConfig */
  39. private $config;
  40. /** @var IUserSession */
  41. private $userSession;
  42. /** @var IL10N */
  43. private $l;
  44. /** @var IURLGenerator */
  45. private $urlGenerator;
  46. /** @var AccessibilityProvider */
  47. private $accessibilityProvider;
  48. /** @var IInitialStateService */
  49. private $initialStateService;
  50. /**
  51. * Settings constructor.
  52. *
  53. * @param string $appName
  54. * @param IConfig $config
  55. * @param IUserSession $userSession
  56. * @param IL10N $l
  57. * @param IURLGenerator $urlGenerator
  58. * @param AccessibilityProvider $accessibilityProvider
  59. */
  60. public function __construct(string $appName,
  61. IConfig $config,
  62. IUserSession $userSession,
  63. IL10N $l,
  64. IURLGenerator $urlGenerator,
  65. AccessibilityProvider $accessibilityProvider,
  66. IInitialStateService $initialStateService) {
  67. $this->appName = $appName;
  68. $this->config = $config;
  69. $this->userSession = $userSession;
  70. $this->l = $l;
  71. $this->urlGenerator = $urlGenerator;
  72. $this->accessibilityProvider = $accessibilityProvider;
  73. $this->initialStateService = $initialStateService;
  74. }
  75. /**
  76. * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
  77. * @since 9.1
  78. */
  79. public function getForm() {
  80. Util::addScript('accessibility', 'accessibility');
  81. Util::addStyle('accessibility', 'style');
  82. $availableConfig = [
  83. 'themes' => $this->accessibilityProvider->getThemes(),
  84. 'fonts' => $this->accessibilityProvider->getFonts(),
  85. 'highcontrast' => $this->accessibilityProvider->getHighContrast()
  86. ];
  87. $userConfig = [
  88. 'highcontrast' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'highcontrast', false),
  89. 'theme' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false),
  90. 'font' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false)
  91. ];
  92. $this->initialStateService->provideInitialState($this->appName, 'available-config', $availableConfig);
  93. $this->initialStateService->provideInitialState($this->appName, 'user-config', $userConfig);
  94. return new TemplateResponse($this->appName, 'settings-personal');
  95. }
  96. /**
  97. * @return string the section ID, e.g. 'sharing'
  98. * @since 9.1
  99. */
  100. public function getSection() {
  101. return $this->appName;
  102. }
  103. /**
  104. * @return int whether the form should be rather on the top or bottom of
  105. * the admin section. The forms are arranged in ascending order of the
  106. * priority values. It is required to return a value between 0 and 100.
  107. *
  108. * E.g.: 70
  109. * @since 9.1
  110. */
  111. public function getPriority() {
  112. return 40;
  113. }
  114. }