Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Circles.php « v1 « Api « lib - github.com/nextcloud/circles.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 06c63e689d42f115b4bf31def6d62921d54ed924 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
/**
 * Circles - Bring cloud-users closer together.
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Maxence Lange <maxence@pontapreta.net>
 * @copyright 2017
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace OCA\Circles\Api\v1;


use OCA\Circles\AppInfo\Application;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\FederatedLink;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\SharingFrame;

class Circles {

	const API_VERSION = [0, 9, 1];

	protected static function getContainer() {
		$app = new Application();

		return $app->getContainer();
	}


	/**
	 * Circles::version()
	 *
	 * returns the current version of the API
	 *
	 * @return int[]
	 */
	public static function version() {
		return self::API_VERSION;
	}


	/**
	 * Circles::createCircle();
	 *
	 * Create a new circle and make the current user its owner.
	 * You must specify type and name. type is one of this value:
	 *
	 * CIRCLES_PERSONAL is 1 or 'personal'
	 * CIRCLES_HIDDEN is 2 or 'hidden'
	 * CIRCLES_PRIVATE is 4 or 'private'
	 * CIRCLES_PUBLIC is 8 or 'public'
	 *
	 * @param $type
	 * @param $name
	 *
	 * @return Circle
	 */
	public static function createCircle($type, $name) {
		$c = self::getContainer();

		return $c->query('CirclesService')
				 ->createCircle($type, $name);
	}


	/**
	 * Circles::joinCircle();
	 *
	 * This function will make the current user joining a circle identified by its Id.
	 *
	 * @param $circleId
	 *
	 * @return Member
	 */
	public static function joinCircle($circleId) {
		$c = self::getContainer();

		return $c->query('CirclesService')
				 ->joinCircle($circleId);
	}


	/**
	 * Circles::leaveCircle();
	 *
	 * This function will make the current user leaving the circle identified by its Id. Will fail
	 * if user is the owner of the circle.
	 *
	 * @param $circleId
	 *
	 * @return Member
	 */
	public static function leaveCircle($circleId) {
		$c = self::getContainer();

		return $c->query('CirclesService')
				 ->leaveCircle($circleId);
	}


	/**
	 * Circles::listCircles();
	 *
	 * This function list all circles fitting a search regarding its name and the level and the
	 * rights from the current user. In case of Hidden circle, name needs to be complete so the
	 * circle is included in the list (or if the current user is the owner)
	 *
	 * example: Circles::listCircles(Circle::CIRCLES_ALL, '', 8, callback); will returns all
	 * circles when the current user is at least an Admin.
	 *
	 * @param $type
	 * @param string $name
	 * @param int $level
	 *
	 * @return Circle[]
	 */
	public static function listCircles($type, $name = '', $level = 0) {
		$c = self::getContainer();

		return $c->query('CirclesService')
				 ->listCircles($type, $name, $level);
	}


	/**
	 * Circles::detailsCircle();
	 *
	 * WARNING - This function is called by the core - WARNING
	 *                 Do not change it
	 *
	 * Returns details on the circle. If the current user is a member, the members list will be
	 * return as well.
	 *
	 * @param $circleId
	 *
	 * @return Circle
	 */
	public static function detailsCircle($circleId) {
		$c = self::getContainer();

		return $c->query('CirclesService')
				 ->detailsCircle($circleId);
	}


	/**
	 * Circles::destroyCircle();
	 *
	 * This function will destroy the circle if the current user is the Owner.
	 *
	 * @param $circleId
	 *
	 * @return mixed
	 */
	public static function destroyCircle($circleId) {
		$c = self::getContainer();

		return $c->query('CirclesService')
				 ->removeCircle($circleId);
	}


	/**
	 * Circles::addMember();
	 *
	 * This function will add a user as member of the circle. Current user need at least to be
	 * Moderator.
	 *
	 * @param $circleId
	 * @param $userId
	 *
	 * @return Member[]
	 */
	public static function addMember($circleId, $userId) {
		$c = self::getContainer();

		return $c->query('MembersService')
				 ->addMember($circleId, $userId);
	}


	/**
	 * Circles::getMember();
	 *
	 * This function will return information on a member of the circle. Current user need at least
	 * to be Member.
	 *
	 * @param $circleId
	 * @param $userId
	 *
	 * @return Member
	 */
	public static function getMember($circleId, $userId) {
		$c = self::getContainer();

		return $c->query('MembersService')
				 ->getMember($circleId, $userId);
	}


	/**
	 * Circles::removeMember();
	 *
	 * This function will remove a member from the circle. Current user needs to be at least
	 * Moderator and have a higher level that the targeted member.
	 *
	 * @param $circleId
	 * @param $userId
	 *
	 * @return Member[]
	 */
	public static function removeMember($circleId, $userId) {
		$c = self::getContainer();

		return $c->query('MembersService')
				 ->removeMember($circleId, $userId);
	}


	/**
	 * Circles::levelMember();
	 *
	 * Edit the level of a member of the circle. The current level of the target needs to be lower
	 * than the user that initiate the process (ie. the current user). The new level of the target
	 * cannot be the same than the current level of the user that initiate the process (ie. the
	 * current user).
	 *
	 * @param $circleId
	 * @param $userId
	 * @param $level
	 *
	 * @return Member[]
	 */
	public static function levelMember($circleId, $userId, $level) {
		$c = self::getContainer();

		return $c->query('MembersService')
				 ->levelMember($circleId, $userId, $level);
	}


	/**
	 * Circles::shareToCircle();
	 *
	 * This function will share an item (array) to the circle identified by its Id.
	 * Source is the app that is sharing the item and type can be used by the app to identified the
	 * payload.
	 *
	 * @param $circleId
	 * @param $source
	 * @param $type
	 * @param array $payload
	 * @param $broadcaster
	 *
	 * @return mixed
	 */
	public static function shareToCircle(
		$circleId, $source, $type, array $payload, $broadcaster
	) {
		$c = self::getContainer();

		$frame = new SharingFrame((string)$source, (string)$type);
		$frame->setCircleId((int)$circleId);
		$frame->setPayload($payload);

		return $c->query('SharesService')
				 ->createFrame($frame, (string)$broadcaster);
	}


	/**
	 * Circles::linkCircle();
	 *
	 * Initiate a link procedure. Current user must be at least Admin of the circle.
	 * circleId is the local circle and remote is the target for the link.
	 * Remote format is: <circle_name>@<remote_host> when remote_host must be a valid HTTPS address.
	 *
	 * @param $circleId
	 * @param $remote
	 *
	 * @return FederatedLink
	 */
	public static function linkCircle($circleId, $remote) {
		$c = self::getContainer();

		return $c->query('FederatedService')
				 ->linkCircle($circleId, $remote);
	}


	/**
	 * Circles::generateLink();
	 *
	 * Returns the link to get access to a local circle.
	 *
	 * @param int $circleId
	 *
	 * @return string
	 */
	public static function generateLink($circleId) {
		return \OC::$server->getURLGenerator()
						   ->linkToRoute('circles.Navigation.navigate') . '#' . $circleId;
	}


	/**
	 * Circles::generateLink();
	 *
	 * Returns the link to get access to a remote circle.
	 *
	 * @param int $circleId
	 *
	 * @return string
	 */
	public static function generateRemoteLink($remote, $circleId) {
		return \OC::$server->getURLGenerator()
						   ->linkToRoute('circles.Navigation.navigate') . '#' . $circleId;
	}

}