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