Personal.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Jos Poortvliet <jos@opensuse.org>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Carl Schwan <carl@carlschwan.eu>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. namespace OCA\FederatedFileSharing\Settings;
  29. use OCA\FederatedFileSharing\FederatedShareProvider;
  30. use OCP\AppFramework\Http\TemplateResponse;
  31. use OCP\AppFramework\Services\IInitialState;
  32. use OCP\Defaults;
  33. use OCP\IURLGenerator;
  34. use OCP\IUserSession;
  35. use OCP\Settings\ISettings;
  36. class Personal implements ISettings {
  37. private FederatedShareProvider $federatedShareProvider;
  38. private IUserSession $userSession;
  39. private Defaults $defaults;
  40. private IInitialState $initialState;
  41. private IURLGenerator $urlGenerator;
  42. public function __construct(
  43. FederatedShareProvider $federatedShareProvider,
  44. IUserSession $userSession,
  45. Defaults $defaults,
  46. IInitialState $initialState,
  47. IURLGenerator $urlGenerator
  48. ) {
  49. $this->federatedShareProvider = $federatedShareProvider;
  50. $this->userSession = $userSession;
  51. $this->defaults = $defaults;
  52. $this->initialState = $initialState;
  53. $this->urlGenerator = $urlGenerator;
  54. }
  55. /**
  56. * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
  57. * @since 9.1
  58. */
  59. public function getForm(): TemplateResponse {
  60. $cloudID = $this->userSession->getUser()->getCloudId();
  61. $url = 'https://nextcloud.com/sharing#' . $cloudID;
  62. $this->initialState->provideInitialState('color', $this->defaults->getDefaultColorPrimary());
  63. $this->initialState->provideInitialState('textColor', $this->defaults->getDefaultTextColorPrimary());
  64. $this->initialState->provideInitialState('logoPath', $this->defaults->getLogo());
  65. $this->initialState->provideInitialState('reference', $url);
  66. $this->initialState->provideInitialState('cloudId', $cloudID);
  67. $this->initialState->provideInitialState('docUrlFederated', $this->urlGenerator->linkToDocs('user-sharing-federated'));
  68. return new TemplateResponse('federatedfilesharing', 'settings-personal', [], TemplateResponse::RENDER_AS_BLANK);
  69. }
  70. /**
  71. * @return string the section ID, e.g. 'sharing'
  72. * @since 9.1
  73. */
  74. public function getSection(): ?string {
  75. if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() ||
  76. $this->federatedShareProvider->isIncomingServer2serverGroupShareEnabled()) {
  77. return 'sharing';
  78. }
  79. return null;
  80. }
  81. /**
  82. * @return int whether the form should be rather on the top or bottom of
  83. * the admin section. The forms are arranged in ascending order of the
  84. * priority values. It is required to return a value between 0 and 100.
  85. *
  86. * E.g.: 70
  87. * @since 9.1
  88. */
  89. public function getPriority(): int {
  90. return 40;
  91. }
  92. }