Personal.php 3.9 KB

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