Admin.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 Lukas Reschke <lukas@statuscode.ch>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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\User_LDAP\Settings;
  26. use OCA\User_LDAP\Configuration;
  27. use OCA\User_LDAP\Helper;
  28. use OCP\AppFramework\Http\TemplateResponse;
  29. use OCP\IL10N;
  30. use OCP\Settings\ISettings;
  31. use OCP\Template;
  32. class Admin implements ISettings {
  33. /** @var IL10N */
  34. private $l;
  35. /**
  36. * @param IL10N $l
  37. */
  38. public function __construct(IL10N $l) {
  39. $this->l = $l;
  40. }
  41. /**
  42. * @return TemplateResponse
  43. */
  44. public function getForm() {
  45. $helper = new Helper(\OC::$server->getConfig());
  46. $prefixes = $helper->getServerConfigurationPrefixes();
  47. if(count($prefixes) === 0) {
  48. $newPrefix = $helper->getNextServerConfigurationPrefix();
  49. $config = new Configuration($newPrefix, false);
  50. $config->setConfiguration($config->getDefaults());
  51. $config->saveConfiguration();
  52. $prefixes[] = $newPrefix;
  53. }
  54. $hosts = $helper->getServerConfigurationHosts();
  55. $wControls = new Template('user_ldap', 'part.wizardcontrols');
  56. $wControls = $wControls->fetchPage();
  57. $sControls = new Template('user_ldap', 'part.settingcontrols');
  58. $sControls = $sControls->fetchPage();
  59. $parameters['serverConfigurationPrefixes'] = $prefixes;
  60. $parameters['serverConfigurationHosts'] = $hosts;
  61. $parameters['settingControls'] = $sControls;
  62. $parameters['wizardControls'] = $wControls;
  63. // assign default values
  64. if(!isset($config)) {
  65. $config = new Configuration('', false);
  66. }
  67. $defaults = $config->getDefaults();
  68. foreach($defaults as $key => $default) {
  69. $parameters[$key.'_default'] = $default;
  70. }
  71. return new TemplateResponse('user_ldap', 'settings', $parameters);
  72. }
  73. /**
  74. * @return string the section ID, e.g. 'sharing'
  75. */
  76. public function getSection() {
  77. return 'ldap';
  78. }
  79. /**
  80. * @return int whether the form should be rather on the top or bottom of
  81. * the admin section. The forms are arranged in ascending order of the
  82. * priority values. It is required to return a value between 0 and 100.
  83. *
  84. * E.g.: 70
  85. */
  86. public function getPriority() {
  87. return 5;
  88. }
  89. }