1
0

Admin.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\User_LDAP\Settings;
  7. use OCA\User_LDAP\Configuration;
  8. use OCA\User_LDAP\Helper;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\IL10N;
  11. use OCP\Settings\IDelegatedSettings;
  12. use OCP\Template;
  13. class Admin implements IDelegatedSettings {
  14. /**
  15. * @param IL10N $l
  16. */
  17. public function __construct(
  18. private IL10N $l,
  19. ) {
  20. }
  21. /**
  22. * @return TemplateResponse
  23. */
  24. public function getForm() {
  25. $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
  26. $prefixes = $helper->getServerConfigurationPrefixes();
  27. if (count($prefixes) === 0) {
  28. $newPrefix = $helper->getNextServerConfigurationPrefix();
  29. $config = new Configuration($newPrefix, false);
  30. $config->setConfiguration($config->getDefaults());
  31. $config->saveConfiguration();
  32. $prefixes[] = $newPrefix;
  33. }
  34. $hosts = $helper->getServerConfigurationHosts();
  35. $wControls = new Template('user_ldap', 'part.wizardcontrols');
  36. $wControls = $wControls->fetchPage();
  37. $sControls = new Template('user_ldap', 'part.settingcontrols');
  38. $sControls = $sControls->fetchPage();
  39. $parameters['serverConfigurationPrefixes'] = $prefixes;
  40. $parameters['serverConfigurationHosts'] = $hosts;
  41. $parameters['settingControls'] = $sControls;
  42. $parameters['wizardControls'] = $wControls;
  43. // assign default values
  44. if (!isset($config)) {
  45. $config = new Configuration('', false);
  46. }
  47. $defaults = $config->getDefaults();
  48. foreach ($defaults as $key => $default) {
  49. $parameters[$key . '_default'] = $default;
  50. }
  51. return new TemplateResponse('user_ldap', 'settings', $parameters);
  52. }
  53. /**
  54. * @return string the section ID, e.g. 'sharing'
  55. */
  56. public function getSection() {
  57. return 'ldap';
  58. }
  59. /**
  60. * @return int whether the form should be rather on the top or bottom of
  61. * the admin section. The forms are arranged in ascending order of the
  62. * priority values. It is required to return a value between 0 and 100.
  63. *
  64. * E.g.: 70
  65. */
  66. public function getPriority() {
  67. return 5;
  68. }
  69. public function getName(): ?string {
  70. return null; // Only one setting in this section
  71. }
  72. public function getAuthorizedAppConfig(): array {
  73. return []; // Custom controller
  74. }
  75. }