1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Circles - Bring cloud-users closer together. |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Maxence Lange <[email protected]> |
9
|
|
|
* @copyright 2017 |
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
|
|
|
|
27
|
|
|
namespace OCA\Circles\Api\v1; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
use OCA\Circles\AppInfo\Application; |
31
|
|
|
use OCA\Circles\Model\Circle; |
32
|
|
|
use OCA\Circles\Model\FederatedLink; |
33
|
|
|
use OCA\Circles\Model\Member; |
34
|
|
|
use OCA\Circles\Model\SharingFrame; |
35
|
|
|
|
36
|
|
|
class Circles { |
37
|
|
|
|
38
|
|
|
const API_VERSION = [0, 9, 1]; |
39
|
|
|
|
40
|
|
|
protected static function getContainer() { |
41
|
|
|
$app = new Application(); |
42
|
|
|
|
43
|
|
|
return $app->getContainer(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Circles::version() |
49
|
|
|
* |
50
|
|
|
* returns the current version of the API |
51
|
|
|
* |
52
|
|
|
* @return int[] |
53
|
|
|
*/ |
54
|
|
|
public static function version() { |
55
|
|
|
return self::API_VERSION; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Circles::createCircle(); |
61
|
|
|
* |
62
|
|
|
* Create a new circle and make the current user its owner. |
63
|
|
|
* You must specify type and name. type is one of this value: |
64
|
|
|
* |
65
|
|
|
* CIRCLES_PERSONAL is 1 or 'personal' |
66
|
|
|
* CIRCLES_HIDDEN is 2 or 'hidden' |
67
|
|
|
* CIRCLES_PRIVATE is 4 or 'private' |
68
|
|
|
* CIRCLES_PUBLIC is 8 or 'public' |
69
|
|
|
* |
70
|
|
|
* @param $type |
71
|
|
|
* @param $name |
72
|
|
|
* |
73
|
|
|
* @return Circle |
74
|
|
|
*/ |
75
|
|
|
public static function createCircle($type, $name) { |
76
|
|
|
$c = self::getContainer(); |
77
|
|
|
|
78
|
|
|
return $c->query('CirclesService') |
79
|
|
|
->createCircle($type, $name); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Circles::joinCircle(); |
85
|
|
|
* |
86
|
|
|
* This function will make the current user joining a circle identified by its Id. |
87
|
|
|
* |
88
|
|
|
* @param $circleId |
89
|
|
|
* |
90
|
|
|
* @return Member |
91
|
|
|
*/ |
92
|
|
|
public static function joinCircle($circleId) { |
93
|
|
|
$c = self::getContainer(); |
94
|
|
|
|
95
|
|
|
return $c->query('CirclesService') |
96
|
|
|
->joinCircle($circleId); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Circles::leaveCircle(); |
102
|
|
|
* |
103
|
|
|
* This function will make the current user leaving the circle identified by its Id. Will fail |
104
|
|
|
* if user is the owner of the circle. |
105
|
|
|
* |
106
|
|
|
* @param $circleId |
107
|
|
|
* |
108
|
|
|
* @return Member |
109
|
|
|
*/ |
110
|
|
|
public static function leaveCircle($circleId) { |
111
|
|
|
$c = self::getContainer(); |
112
|
|
|
|
113
|
|
|
return $c->query('CirclesService') |
114
|
|
|
->leaveCircle($circleId); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Circles::listCircles(); |
120
|
|
|
* |
121
|
|
|
* This function list all circles fitting a search regarding its name and the level and the |
122
|
|
|
* rights from the current user. In case of Hidden circle, name needs to be complete so the |
123
|
|
|
* circle is included in the list (or if the current user is the owner) |
124
|
|
|
* |
125
|
|
|
* example: Circles::listCircles(Circle::CIRCLES_ALL, '', 8, callback); will returns all |
126
|
|
|
* circles when the current user is at least an Admin. |
127
|
|
|
* |
128
|
|
|
* @param $type |
129
|
|
|
* @param string $name |
130
|
|
|
* @param int $level |
131
|
|
|
* |
132
|
|
|
* @return Circle[] |
133
|
|
|
*/ |
134
|
|
|
public static function listCircles($type, $name = '', $level = 0) { |
135
|
|
|
$c = self::getContainer(); |
136
|
|
|
|
137
|
|
|
return $c->query('CirclesService') |
138
|
|
|
->listCircles($type, $name, $level); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Circles::detailsCircle(); |
144
|
|
|
* |
145
|
|
|
* WARNING - This function is called by the core - WARNING |
146
|
|
|
* Do not change it |
147
|
|
|
* |
148
|
|
|
* Returns details on the circle. If the current user is a member, the members list will be |
149
|
|
|
* return as well. |
150
|
|
|
* |
151
|
|
|
* @param $circleId |
152
|
|
|
* |
153
|
|
|
* @return Circle |
154
|
|
|
*/ |
155
|
|
|
public static function detailsCircle($circleId) { |
156
|
|
|
$c = self::getContainer(); |
157
|
|
|
|
158
|
|
|
return $c->query('CirclesService') |
159
|
|
|
->detailsCircle($circleId); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Circles::destroyCircle(); |
165
|
|
|
* |
166
|
|
|
* This function will destroy the circle if the current user is the Owner. |
167
|
|
|
* |
168
|
|
|
* @param $circleId |
169
|
|
|
* |
170
|
|
|
* @return mixed |
171
|
|
|
*/ |
172
|
|
|
public static function destroyCircle($circleId) { |
173
|
|
|
$c = self::getContainer(); |
174
|
|
|
|
175
|
|
|
return $c->query('CirclesService') |
176
|
|
|
->removeCircle($circleId); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Circles::addMember(); |
182
|
|
|
* |
183
|
|
|
* This function will add a user as member of the circle. Current user need at least to be |
184
|
|
|
* Moderator. |
185
|
|
|
* |
186
|
|
|
* @param $circleId |
187
|
|
|
* @param $userId |
188
|
|
|
* |
189
|
|
|
* @return Member[] |
190
|
|
|
*/ |
191
|
|
|
public static function addMember($circleId, $userId) { |
192
|
|
|
$c = self::getContainer(); |
193
|
|
|
|
194
|
|
|
return $c->query('MembersService') |
195
|
|
|
->addMember($circleId, $userId); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Circles::getMember(); |
201
|
|
|
* |
202
|
|
|
* This function will return information on a member of the circle. Current user need at least |
203
|
|
|
* to be Member. |
204
|
|
|
* |
205
|
|
|
* @param $circleId |
206
|
|
|
* @param $userId |
207
|
|
|
* |
208
|
|
|
* @return Member |
209
|
|
|
*/ |
210
|
|
|
public static function getMember($circleId, $userId) { |
211
|
|
|
$c = self::getContainer(); |
212
|
|
|
|
213
|
|
|
return $c->query('MembersService') |
214
|
|
|
->getMember($circleId, $userId); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Circles::removeMember(); |
220
|
|
|
* |
221
|
|
|
* This function will remove a member from the circle. Current user needs to be at least |
222
|
|
|
* Moderator and have a higher level that the targeted member. |
223
|
|
|
* |
224
|
|
|
* @param $circleId |
225
|
|
|
* @param $userId |
226
|
|
|
* |
227
|
|
|
* @return Member[] |
228
|
|
|
*/ |
229
|
|
|
public static function removeMember($circleId, $userId) { |
230
|
|
|
$c = self::getContainer(); |
231
|
|
|
|
232
|
|
|
return $c->query('MembersService') |
233
|
|
|
->removeMember($circleId, $userId); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Circles::levelMember(); |
239
|
|
|
* |
240
|
|
|
* Edit the level of a member of the circle. The current level of the target needs to be lower |
241
|
|
|
* than the user that initiate the process (ie. the current user). The new level of the target |
242
|
|
|
* cannot be the same than the current level of the user that initiate the process (ie. the |
243
|
|
|
* current user). |
244
|
|
|
* |
245
|
|
|
* @param $circleId |
246
|
|
|
* @param $userId |
247
|
|
|
* @param $level |
248
|
|
|
* |
249
|
|
|
* @return Member[] |
250
|
|
|
*/ |
251
|
|
|
public static function levelMember($circleId, $userId, $level) { |
252
|
|
|
$c = self::getContainer(); |
253
|
|
|
|
254
|
|
|
return $c->query('MembersService') |
255
|
|
|
->levelMember($circleId, $userId, $level); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Circles::shareToCircle(); |
261
|
|
|
* |
262
|
|
|
* This function will share an item (array) to the circle identified by its Id. |
263
|
|
|
* Source is the app that is sharing the item and type can be used by the app to identified the |
264
|
|
|
* payload. |
265
|
|
|
* |
266
|
|
|
* @param $circleId |
267
|
|
|
* @param $source |
268
|
|
|
* @param $type |
269
|
|
|
* @param array $payload |
270
|
|
|
* @param $broadcaster |
271
|
|
|
* |
272
|
|
|
* @return mixed |
273
|
|
|
*/ |
274
|
|
|
public static function shareToCircle( |
275
|
|
|
$circleId, $source, $type, array $payload, $broadcaster |
276
|
|
|
) { |
277
|
|
|
$c = self::getContainer(); |
278
|
|
|
|
279
|
|
|
$frame = new SharingFrame((string)$source, (string)$type); |
280
|
|
|
$frame->setCircleId((int)$circleId); |
281
|
|
|
$frame->setPayload($payload); |
282
|
|
|
|
283
|
|
|
return $c->query('SharesService') |
284
|
|
|
->createFrame($frame, (string)$broadcaster); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Circles::linkCircle(); |
290
|
|
|
* |
291
|
|
|
* Initiate a link procedure. Current user must be at least Admin of the circle. |
292
|
|
|
* circleId is the local circle and remote is the target for the link. |
293
|
|
|
* Remote format is: <circle_name>@<remote_host> when remote_host must be a valid HTTPS address. |
294
|
|
|
* |
295
|
|
|
* @param $circleId |
296
|
|
|
* @param $remote |
297
|
|
|
* |
298
|
|
|
* @return FederatedLink |
299
|
|
|
*/ |
300
|
|
|
public static function linkCircle($circleId, $remote) { |
301
|
|
|
$c = self::getContainer(); |
302
|
|
|
|
303
|
|
|
return $c->query('FederatedService') |
304
|
|
|
->linkCircle($circleId, $remote); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Circles::generateLink(); |
310
|
|
|
* |
311
|
|
|
* Returns the link to get access to a local circle. |
312
|
|
|
* |
313
|
|
|
* @param int $circleId |
314
|
|
|
* |
315
|
|
|
* @return string |
316
|
|
|
*/ |
317
|
|
|
public static function generateLink($circleId) { |
318
|
|
|
return \OC::$server->getURLGenerator() |
319
|
|
|
->linkToRoute('circles.Navigation.navigate') . '#' . $circleId; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Circles::generateLink(); |
325
|
|
|
* |
326
|
|
|
* Returns the link to get access to a remote circle. |
327
|
|
|
* |
328
|
|
|
* @param int $circleId |
329
|
|
|
* |
330
|
|
|
* @return string |
331
|
|
|
*/ |
332
|
|
|
public static function generateRemoteLink($remote, $circleId) { |
|
|
|
|
333
|
|
|
return \OC::$server->getURLGenerator() |
334
|
|
|
->linkToRoute('circles.Navigation.navigate') . '#' . $circleId; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.