Personal.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\FederatedFileSharing\Settings;
  8. use OCA\FederatedFileSharing\FederatedShareProvider;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\AppFramework\Services\IInitialState;
  11. use OCP\Defaults;
  12. use OCP\IURLGenerator;
  13. use OCP\IUserSession;
  14. use OCP\Settings\ISettings;
  15. class Personal implements ISettings {
  16. private FederatedShareProvider $federatedShareProvider;
  17. private IUserSession $userSession;
  18. private Defaults $defaults;
  19. private IInitialState $initialState;
  20. private IURLGenerator $urlGenerator;
  21. public function __construct(
  22. FederatedShareProvider $federatedShareProvider,
  23. IUserSession $userSession,
  24. Defaults $defaults,
  25. IInitialState $initialState,
  26. IURLGenerator $urlGenerator
  27. ) {
  28. $this->federatedShareProvider = $federatedShareProvider;
  29. $this->userSession = $userSession;
  30. $this->defaults = $defaults;
  31. $this->initialState = $initialState;
  32. $this->urlGenerator = $urlGenerator;
  33. }
  34. /**
  35. * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
  36. * @since 9.1
  37. */
  38. public function getForm(): TemplateResponse {
  39. $cloudID = $this->userSession->getUser()->getCloudId();
  40. $url = 'https://nextcloud.com/sharing#' . $cloudID;
  41. $this->initialState->provideInitialState('color', $this->defaults->getDefaultColorPrimary());
  42. $this->initialState->provideInitialState('textColor', $this->defaults->getDefaultTextColorPrimary());
  43. $this->initialState->provideInitialState('logoPath', $this->defaults->getLogo());
  44. $this->initialState->provideInitialState('reference', $url);
  45. $this->initialState->provideInitialState('cloudId', $cloudID);
  46. $this->initialState->provideInitialState('docUrlFederated', $this->urlGenerator->linkToDocs('user-sharing-federated'));
  47. return new TemplateResponse('federatedfilesharing', 'settings-personal', [], TemplateResponse::RENDER_AS_BLANK);
  48. }
  49. /**
  50. * @return string the section ID, e.g. 'sharing'
  51. * @since 9.1
  52. */
  53. public function getSection(): ?string {
  54. if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() ||
  55. $this->federatedShareProvider->isIncomingServer2serverGroupShareEnabled()) {
  56. return 'sharing';
  57. }
  58. return null;
  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. * @since 9.1
  67. */
  68. public function getPriority(): int {
  69. return 40;
  70. }
  71. }