ServerDevNotice.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Jan C. Borchardt <hey@jancborchardt.net>
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Settings\Settings\Personal;
  27. use OCA\Viewer\Event\LoadViewer;
  28. use OCP\AppFramework\Http\TemplateResponse;
  29. use OCP\AppFramework\Services\IInitialState;
  30. use OCP\EventDispatcher\IEventDispatcher;
  31. use OCP\Files\IRootFolder;
  32. use OCP\IURLGenerator;
  33. use OCP\IUserSession;
  34. use OCP\Settings\ISettings;
  35. use OCP\Support\Subscription\IRegistry;
  36. use OCP\Util;
  37. class ServerDevNotice implements ISettings {
  38. /** @var IRegistry */
  39. private $registry;
  40. /** @var IEventDispatcher */
  41. private $eventDispatcher;
  42. /** @var IRootFolder */
  43. private $rootFolder;
  44. /** @var IUserSession */
  45. private $userSession;
  46. /** @var IInitialState */
  47. private $initialState;
  48. /** @var IURLGenerator */
  49. private $urlGenerator;
  50. public function __construct(IRegistry $registry,
  51. IEventDispatcher $eventDispatcher,
  52. IRootFolder $rootFolder,
  53. IUserSession $userSession,
  54. IInitialState $initialState,
  55. IURLGenerator $urlGenerator) {
  56. $this->registry = $registry;
  57. $this->eventDispatcher = $eventDispatcher;
  58. $this->rootFolder = $rootFolder;
  59. $this->userSession = $userSession;
  60. $this->initialState = $initialState;
  61. $this->urlGenerator = $urlGenerator;
  62. }
  63. /**
  64. * @return TemplateResponse
  65. */
  66. public function getForm(): TemplateResponse {
  67. $userFolder = $this->rootFolder->getUserFolder($this->userSession->getUser()->getUID());
  68. $hasInitialState = false;
  69. // If the Reasons to use Nextcloud.pdf file is here, let's init Viewer, also check that Viewer is there
  70. if (class_exists(LoadViewer::class) && $userFolder->nodeExists('Reasons to use Nextcloud.pdf')) {
  71. /**
  72. * @psalm-suppress UndefinedClass, InvalidArgument
  73. */
  74. $this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());
  75. $hasInitialState = true;
  76. }
  77. // Always load the script
  78. Util::addScript('settings', 'vue-settings-nextcloud-pdf');
  79. $this->initialState->provideInitialState('has-reasons-use-nextcloud-pdf', $hasInitialState);
  80. return new TemplateResponse('settings', 'settings/personal/development.notice', [
  81. 'reasons-use-nextcloud-pdf-link' => $this->urlGenerator->linkToRoute('settings.Reasons.getPdf')
  82. ]);
  83. }
  84. /**
  85. * @return string|null the section ID, e.g. 'sharing'
  86. */
  87. public function getSection(): ?string {
  88. if ($this->registry->delegateHasValidSubscription()) {
  89. return null;
  90. }
  91. return 'personal-info';
  92. }
  93. /**
  94. * @return int whether the form should be rather on the top or bottom of
  95. * the admin section. The forms are arranged in ascending order of the
  96. * priority values. It is required to return a value between 0 and 100.
  97. *
  98. * E.g.: 70
  99. */
  100. public function getPriority(): int {
  101. return 1000;
  102. }
  103. }