DashboardManager.php 3.6 KB

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