Completed
Push — master ( fa4c5d...fa4c5d )
by Maxence
05:16 queued 02:40
created

Circles::settingsCircle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
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
	/**
165
	 * Circles::settingsCircle();
166
	 *
167
	 * Save the settings. Settings is an array and current user need to be an admin
168
	 *
169
	 * @param $circleId
170
	 * @param array $settings
171
	 *
172
	 * @return Circle
173
	 */
174
	public static function settingsCircle($circleId, array $settings) {
175
		$c = self::getContainer();
176
177
		return $c->query('CirclesService')
178
				 ->settingsCircle($circleId, $settings);
179
	}
180
181
182
	/**
183
	 * Circles::destroyCircle();
184
	 *
185
	 * This function will destroy the circle if the current user is the Owner.
186
	 *
187
	 * @param $circleId
188
	 *
189
	 * @return mixed
190
	 */
191
	public static function destroyCircle($circleId) {
192
		$c = self::getContainer();
193
194
		return $c->query('CirclesService')
195
				 ->removeCircle($circleId);
196
	}
197
198
199
	/**
200
	 * Circles::addMember();
201
	 *
202
	 * This function will add a user as member of the circle. Current user need at least to be
203
	 * Moderator.
204
	 *
205
	 * @param $circleId
206
	 * @param $userId
207
	 *
208
	 * @return Member[]
209
	 */
210
	public static function addMember($circleId, $userId) {
211
		$c = self::getContainer();
212
213
		return $c->query('MembersService')
214
				 ->addMember($circleId, $userId);
215
	}
216
217
218
	/**
219
	 * Circles::getMember();
220
	 *
221
	 * This function will return information on a member of the circle. Current user need at least
222
	 * to be Member.
223
	 *
224
	 * @param $circleId
225
	 * @param $userId
226
	 *
227
	 * @return Member
228
	 */
229
	public static function getMember($circleId, $userId) {
230
		$c = self::getContainer();
231
232
		return $c->query('MembersService')
233
				 ->getMember($circleId, $userId);
234
	}
235
236
237
	/**
238
	 * Circles::removeMember();
239
	 *
240
	 * This function will remove a member from the circle. Current user needs to be at least
241
	 * Moderator and have a higher level that the targeted member.
242
	 *
243
	 * @param $circleId
244
	 * @param $userId
245
	 *
246
	 * @return Member[]
247
	 */
248
	public static function removeMember($circleId, $userId) {
249
		$c = self::getContainer();
250
251
		return $c->query('MembersService')
252
				 ->removeMember($circleId, $userId);
253
	}
254
255
256
	/**
257
	 * Circles::levelMember();
258
	 *
259
	 * Edit the level of a member of the circle. The current level of the target needs to be lower
260
	 * than the user that initiate the process (ie. the current user). The new level of the target
261
	 * cannot be the same than the current level of the user that initiate the process (ie. the
262
	 * current user).
263
	 *
264
	 * @param $circleId
265
	 * @param $userId
266
	 * @param $level
267
	 *
268
	 * @return Member[]
269
	 */
270
	public static function levelMember($circleId, $userId, $level) {
271
		$c = self::getContainer();
272
273
		return $c->query('MembersService')
274
				 ->levelMember($circleId, $userId, $level);
275
	}
276
277
278
	/**
279
	 * Circles::shareToCircle();
280
	 *
281
	 * This function will share an item (array) to the circle identified by its Id.
282
	 * Source is the app that is sharing the item and type can be used by the app to identified the
283
	 * payload.
284
	 *
285
	 * @param $circleId
286
	 * @param $source
287
	 * @param $type
288
	 * @param array $payload
289
	 * @param $broadcaster
290
	 *
291
	 * @return mixed
292
	 */
293
	public static function shareToCircle(
294
		$circleId, $source, $type, array $payload, $broadcaster
295
	) {
296
		$c = self::getContainer();
297
298
		$frame = new SharingFrame((string)$source, (string)$type);
299
		$frame->setCircleId((int)$circleId);
300
		$frame->setPayload($payload);
301
302
		return $c->query('SharesService')
303
				 ->createFrame($frame, (string)$broadcaster);
304
	}
305
306
307
	/**
308
	 * Circles::linkCircle();
309
	 *
310
	 * Initiate a link procedure. Current user must be at least Admin of the circle.
311
	 * circleId is the local circle and remote is the target for the link.
312
	 * Remote format is: <circle_name>@<remote_host> when remote_host must be a valid HTTPS address.
313
	 *
314
	 * @param $circleId
315
	 * @param $remote
316
	 *
317
	 * @return FederatedLink
318
	 */
319
	public static function linkCircle($circleId, $remote) {
320
		$c = self::getContainer();
321
322
		return $c->query('FederatedService')
323
				 ->linkCircle($circleId, $remote);
324
	}
325
326
327
	/**
328
	 * Circles::generateLink();
329
	 *
330
	 * Returns the link to get access to a local circle.
331
	 *
332
	 * @param int $circleId
333
	 *
334
	 * @return string
335
	 */
336
	public static function generateLink($circleId) {
337
		return \OC::$server->getURLGenerator()
338
						   ->linkToRoute('circles.Navigation.navigate') . '#' . $circleId;
339
	}
340
341
342
	/**
343
	 * Circles::generateLink();
344
	 *
345
	 * Returns the link to get access to a remote circle.
346
	 *
347
	 * @param int $circleId
348
	 *
349
	 * @return string
350
	 */
351
	public static function generateRemoteLink($remote, $circleId) {
0 ignored issues
show
Unused Code introduced by
The parameter $remote is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
352
		return \OC::$server->getURLGenerator()
353
						   ->linkToRoute('circles.Navigation.navigate') . '#' . $circleId;
354
	}
355
356
}