ServerDevNotice.php 2.7 KB

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