Admin.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  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\User_LDAP\Settings;
  27. use OCA\User_LDAP\Configuration;
  28. use OCA\User_LDAP\Helper;
  29. use OCP\AppFramework\Http\TemplateResponse;
  30. use OCP\IL10N;
  31. use OCP\Settings\IDelegatedSettings;
  32. use OCP\Template;
  33. class Admin implements IDelegatedSettings {
  34. /** @var IL10N */
  35. private $l;
  36. /**
  37. * @param IL10N $l
  38. */
  39. public function __construct(IL10N $l) {
  40. $this->l = $l;
  41. }
  42. /**
  43. * @return TemplateResponse
  44. */
  45. public function getForm() {
  46. $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
  47. $prefixes = $helper->getServerConfigurationPrefixes();
  48. if (count($prefixes) === 0) {
  49. $newPrefix = $helper->getNextServerConfigurationPrefix();
  50. $config = new Configuration($newPrefix, false);
  51. $config->setConfiguration($config->getDefaults());
  52. $config->saveConfiguration();
  53. $prefixes[] = $newPrefix;
  54. }
  55. $hosts = $helper->getServerConfigurationHosts();
  56. $wControls = new Template('user_ldap', 'part.wizardcontrols');
  57. $wControls = $wControls->fetchPage();
  58. $sControls = new Template('user_ldap', 'part.settingcontrols');
  59. $sControls = $sControls->fetchPage();
  60. $parameters['serverConfigurationPrefixes'] = $prefixes;
  61. $parameters['serverConfigurationHosts'] = $hosts;
  62. $parameters['settingControls'] = $sControls;
  63. $parameters['wizardControls'] = $wControls;
  64. // assign default values
  65. if (!isset($config)) {
  66. $config = new Configuration('', false);
  67. }
  68. $defaults = $config->getDefaults();
  69. foreach ($defaults as $key => $default) {
  70. $parameters[$key.'_default'] = $default;
  71. }
  72. return new TemplateResponse('user_ldap', 'settings', $parameters);
  73. }
  74. /**
  75. * @return string the section ID, e.g. 'sharing'
  76. */
  77. public function getSection() {
  78. return 'ldap';
  79. }
  80. /**
  81. * @return int whether the form should be rather on the top or bottom of
  82. * the admin section. The forms are arranged in ascending order of the
  83. * priority values. It is required to return a value between 0 and 100.
  84. *
  85. * E.g.: 70
  86. */
  87. public function getPriority() {
  88. return 5;
  89. }
  90. public function getName(): ?string {
  91. return null; // Only one setting in this section
  92. }
  93. public function getAuthorizedAppConfig(): array {
  94. return []; // Custom controller
  95. }
  96. }