1
0

Admin.php 2.3 KB

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