ServerDevNotice.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\Settings\Settings\Personal;
  7. use OCA\Viewer\Event\LoadViewer;
  8. use OCP\AppFramework\Http\TemplateResponse;
  9. use OCP\AppFramework\Services\IInitialState;
  10. use OCP\EventDispatcher\IEventDispatcher;
  11. use OCP\Files\IRootFolder;
  12. use OCP\IURLGenerator;
  13. use OCP\IUserSession;
  14. use OCP\Settings\ISettings;
  15. use OCP\Support\Subscription\IRegistry;
  16. use OCP\Util;
  17. class ServerDevNotice implements ISettings {
  18. public function __construct(
  19. private IRegistry $registry,
  20. private IEventDispatcher $eventDispatcher,
  21. private IRootFolder $rootFolder,
  22. private IUserSession $userSession,
  23. private IInitialState $initialState,
  24. private IURLGenerator $urlGenerator,
  25. ) {
  26. }
  27. /**
  28. * @return TemplateResponse
  29. */
  30. public function getForm(): TemplateResponse {
  31. $userFolder = $this->rootFolder->getUserFolder($this->userSession->getUser()->getUID());
  32. $hasInitialState = false;
  33. // If the Reasons to use Nextcloud.pdf file is here, let's init Viewer, also check that Viewer is there
  34. if (class_exists(LoadViewer::class) && $userFolder->nodeExists('Reasons to use Nextcloud.pdf')) {
  35. /**
  36. * @psalm-suppress UndefinedClass, InvalidArgument
  37. */
  38. $this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());
  39. $hasInitialState = true;
  40. }
  41. // Always load the script
  42. Util::addScript('settings', 'vue-settings-nextcloud-pdf');
  43. $this->initialState->provideInitialState('has-reasons-use-nextcloud-pdf', $hasInitialState);
  44. return new TemplateResponse('settings', 'settings/personal/development.notice', [
  45. 'reasons-use-nextcloud-pdf-link' => $this->urlGenerator->linkToRoute('settings.Reasons.getPdf')
  46. ]);
  47. }
  48. /**
  49. * @return string|null the section ID, e.g. 'sharing'
  50. */
  51. public function getSection(): ?string {
  52. if ($this->registry->delegateHasValidSubscription()) {
  53. return null;
  54. }
  55. return 'personal-info';
  56. }
  57. /**
  58. * @return int whether the form should be rather on the top or bottom of
  59. * the admin section. The forms are arranged in ascending order of the
  60. * priority values. It is required to return a value between 0 and 100.
  61. *
  62. * E.g.: 70
  63. */
  64. public function getPriority(): int {
  65. return 1000;
  66. }
  67. }