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