ServerDevNotice.php 3.6 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. // viewer is default enabled and this makes a zero-cost assertion for Psalm
  70. assert(class_exists(LoadViewer::class));
  71. // If the Reasons to use Nextcloud.pdf file is here, let's init Viewer
  72. if ($userFolder->nodeExists('Reasons to use Nextcloud.pdf')) {
  73. $this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());
  74. $hasInitialState = true;
  75. }
  76. // Always load the script
  77. Util::addScript('settings', 'vue-settings-nextcloud-pdf');
  78. $this->initialState->provideInitialState('has-reasons-use-nextcloud-pdf', $hasInitialState);
  79. return new TemplateResponse('settings', 'settings/personal/development.notice', [
  80. 'reasons-use-nextcloud-pdf-link' => $this->urlGenerator->linkToRoute('settings.Reasons.getPdf')
  81. ]);
  82. }
  83. /**
  84. * @return string|null the section ID, e.g. 'sharing'
  85. */
  86. public function getSection(): ?string {
  87. if ($this->registry->delegateHasValidSubscription()) {
  88. return null;
  89. }
  90. return 'personal-info';
  91. }
  92. /**
  93. * @return int whether the form should be rather on the top or bottom of
  94. * the admin section. The forms are arranged in ascending order of the
  95. * priority values. It is required to return a value between 0 and 100.
  96. *
  97. * E.g.: 70
  98. */
  99. public function getPriority(): int {
  100. return 1000;
  101. }
  102. }