DashboardManager.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Nextcloud - Dashboard app
  5. *
  6. * This file is licensed under the Affero General Public License version 3 or
  7. * later. See the COPYING file.
  8. *
  9. * @author Maxence Lange <maxence@artificial-owl.com>
  10. * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OC\Dashboard;
  28. use OCP\Dashboard\Exceptions\DashboardAppNotAvailableException;
  29. use OCP\Dashboard\IDashboardManager;
  30. use OCP\Dashboard\Model\IWidgetConfig;
  31. use OCP\Dashboard\Service\IEventsService;
  32. use OCP\Dashboard\Service\IWidgetsService;
  33. /**
  34. * Class DashboardManager
  35. *
  36. * @package OC\Dashboard
  37. */
  38. class DashboardManager implements IDashboardManager {
  39. /** @var IWidgetsService */
  40. private $widgetsService;
  41. /** @var IEventsService */
  42. private $eventsService;
  43. /**
  44. * @param IEventsService $eventsService
  45. */
  46. public function registerEventsService(IEventsService $eventsService) {
  47. $this->eventsService = $eventsService;
  48. }
  49. /**
  50. * @param IWidgetsService $widgetsService
  51. */
  52. public function registerWidgetsService(IWidgetsService $widgetsService) {
  53. $this->widgetsService = $widgetsService;
  54. }
  55. /**
  56. * @param string $widgetId
  57. * @param string $userId
  58. *
  59. * @return IWidgetConfig
  60. * @throws DashboardAppNotAvailableException
  61. */
  62. public function getWidgetConfig(string $widgetId, string $userId): IWidgetConfig {
  63. return $this->getWidgetsService()->getWidgetConfig($widgetId, $userId);
  64. }
  65. /**
  66. * @param string $widgetId
  67. * @param array $users
  68. * @param array $payload
  69. * @param string $uniqueId
  70. *
  71. * @throws DashboardAppNotAvailableException
  72. */
  73. public function createUsersEvent(string $widgetId, array $users, array $payload, string $uniqueId = '') {
  74. $this->getEventsService()->createUsersEvent($widgetId, $users, $payload, $uniqueId);
  75. }
  76. /**
  77. * @param string $widgetId
  78. * @param array $groups
  79. * @param array $payload
  80. * @param string $uniqueId
  81. *
  82. * @throws DashboardAppNotAvailableException
  83. */
  84. public function createGroupsEvent(string $widgetId, array $groups, array $payload, string $uniqueId = '') {
  85. $this->getEventsService()->createGroupsEvent($widgetId, $groups, $payload, $uniqueId);
  86. }
  87. /**
  88. * @param string $widgetId
  89. * @param array $payload
  90. * @param string $uniqueId
  91. *
  92. * @throws DashboardAppNotAvailableException
  93. */
  94. public function createGlobalEvent(string $widgetId, array $payload, string $uniqueId = '') {
  95. $this->getEventsService()->createGlobalEvent($widgetId, $payload, $uniqueId);
  96. }
  97. /**
  98. * @return IWidgetsService
  99. * @throws DashboardAppNotAvailableException
  100. */
  101. private function getWidgetsService() {
  102. if ($this->widgetsService === null) {
  103. throw new DashboardAppNotAvailableException('No IWidgetsService registered');
  104. }
  105. return $this->widgetsService;
  106. }
  107. /**
  108. * @return IEventsService
  109. * @throws DashboardAppNotAvailableException
  110. */
  111. private function getEventsService() {
  112. if ($this->eventsService === null) {
  113. throw new DashboardAppNotAvailableException('No IEventsService registered');
  114. }
  115. return $this->eventsService;
  116. }
  117. }