Completed
Push — master ( 8b683f...7025f1 )
by Morris
29:10 queued 12:40
created

CloudFederationShare::setProtocol()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2018 Bjoern Schiessle <[email protected]>
4
 *
5
 * @license GNU AGPL version 3 or any later version
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as
9
 * published by the Free Software Foundation, either version 3 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
namespace OC\Federation;
23
24
use OCP\Federation\ICloudFederationShare;
25
26
class CloudFederationShare implements ICloudFederationShare {
27
28
	private $share = [
29
		'shareWith' => '',
30
		'shareType' => '',
31
		'name' => '',
32
		'resourceType' => '',
33
		'description' => '',
34
		'providerId' => '',
35
		'owner' => '',
36
		'ownerDisplayName' => '',
37
		'sharedBy' => '',
38
		'sharedByDisplayName' => '',
39
		'protocol' => []
40
	];
41
42
	/**
43
	 * get a CloudFederationShare Object to prepare a share you want to send
44
	 *
45
	 * @param string $shareWith
46
	 * @param string $name resource name (e.g. document.odt)
47
	 * @param string $description share description (optional)
48
	 * @param string $providerId resource UID on the provider side
49
	 * @param string $owner provider specific UID of the user who owns the resource
50
	 * @param string $ownerDisplayName display name of the user who shared the item
51
	 * @param string $sharedBy provider specific UID of the user who shared the resource
52
	 * @param string $sharedByDisplayName display name of the user who shared the resource
53
	 * @param string $shareType ('group' or 'user' share)
54
	 * @param string $resourceType ('file', 'calendar',...)
55
	 * @param string $sharedSecret
56
	 */
57
	public function __construct($shareWith = '',
58
								$name = '',
59
								$description = '',
60
								$providerId = '',
61
								$owner = '',
62
								$ownerDisplayName = '',
63
								$sharedBy = '',
64
								$sharedByDisplayName = '',
65
								$shareType = '',
66
								$resourceType = '',
67
								$sharedSecret = ''
68
	) {
69
		$this->setShareWith($shareWith);
70
		$this->setResourceName($name);
71
		$this->setDescription($description);
72
		$this->setProviderId($providerId);
73
		$this->setOwner($owner);
74
		$this->setOwnerDisplayName($ownerDisplayName);
75
		$this->setSharedBy($sharedBy);
76
		$this->setSharedByDisplayName($sharedByDisplayName);
77
		$this->setProtocol([
78
			'name' => 'webdav',
79
			'options' => [
80
				'sharedSecret' => $sharedSecret,
81
				'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions'
82
			]
83
		]);
84
		$this->setShareType($shareType);
85
		$this->setResourceType($resourceType);
86
87
	}
88
89
	/**
90
	 * set uid of the recipient
91
	 *
92
	 * @param string $user
93
	 *
94
	 * @since 14.0.0
95
	 */
96
	public function setShareWith($user) {
97
		$this->share['shareWith'] = $user;
98
	}
99
100
	/**
101
	 * set resource name (e.g. document.odt)
102
	 *
103
	 * @param string $name
104
	 *
105
	 * @since 14.0.0
106
	 */
107
	public function setResourceName($name) {
108
		$this->share['name'] = $name;
109
	}
110
111
	/**
112
	 * set resource type (e.g. file, calendar, contact,...)
113
	 *
114
	 * @param string $resourceType
115
	 *
116
	 * @since 14.0.0
117
	 */
118
	public function setResourceType($resourceType) {
119
		$this->share['resourceType'] = $resourceType;
120
	}
121
122
	/**
123
	 * set resource description (optional)
124
	 *
125
	 * @param string $description
126
	 *
127
	 * @since 14.0.0
128
	 */
129
	public function setDescription($description) {
130
		$this->share['description'] = $description;
131
	}
132
133
	/**
134
	 * set provider ID (e.g. file ID)
135
	 *
136
	 * @param string $providerId
137
	 *
138
	 * @since 14.0.0
139
	 */
140
	public function setProviderId($providerId) {
141
		$this->share['providerId'] = $providerId;
142
	}
143
144
	/**
145
	 * set owner UID
146
	 *
147
	 * @param string $owner
148
	 *
149
	 * @since 14.0.0
150
	 */
151
	public function setOwner($owner) {
152
		$this->share['owner'] = $owner;
153
	}
154
155
	/**
156
	 * set owner display name
157
	 *
158
	 * @param string $ownerDisplayName
159
	 *
160
	 * @since 14.0.0
161
	 */
162
	public function setOwnerDisplayName($ownerDisplayName) {
163
		$this->share['ownerDisplayName'] = $ownerDisplayName;
164
	}
165
166
	/**
167
	 * set UID of the user who sends the share
168
	 *
169
	 * @param string $sharedBy
170
	 *
171
	 * @since 14.0.0
172
	 */
173
	public function setSharedBy($sharedBy) {
174
		$this->share['sharedBy'] = $sharedBy;
175
	}
176
177
	/**
178
	 * set display name of the user who sends the share
179
	 *
180
	 * @param $sharedByDisplayName
181
	 *
182
	 * @since 14.0.0
183
	 */
184
	public function setSharedByDisplayName($sharedByDisplayName) {
185
		$this->share['sharedByDisplayName'] = $sharedByDisplayName;
186
	}
187
188
	/**
189
	 * set protocol specification
190
	 *
191
	 * @param array $protocol
192
	 *
193
	 * @since 14.0.0
194
	 */
195
	public function setProtocol(array $protocol) {
196
		$this->share['protocol'] = $protocol;
197
	}
198
199
	/**
200
	 * share type (group or user)
201
	 *
202
	 * @param string $shareType
203
	 *
204
	 * @since 14.0.0
205
	 */
206
	public function setShareType($shareType) {
207
		$this->share['shareType'] = $shareType;
208
	}
209
210
	/**
211
	 * get the whole share, ready to send out
212
	 *
213
	 * @return array
214
	 *
215
	 * @since 14.0.0
216
	 */
217
	public function getShare() {
218
		return $this->share;
219
	}
220
221
	/**
222
	 * get uid of the recipient
223
	 *
224
	 * @return string
225
	 *
226
	 * @since 14.0.0
227
	 */
228
	public function getShareWith() {
229
		return $this->share['shareWith'];
230
	}
231
232
	/**
233
	 * get resource name (e.g. file, calendar, contact,...)
234
	 *
235
	 * @return string
236
	 *
237
	 * @since 14.0.0
238
	 */
239
	public function getResourceName() {
240
		return $this->share['name'];
241
	}
242
243
	/**
244
	 * get resource type (e.g. file, calendar, contact,...)
245
	 *
246
	 * @return string
247
	 *
248
	 * @since 14.0.0
249
	 */
250
	public function getResourceType() {
251
		return $this->share['resourceType'];
252
	}
253
254
	/**
255
	 * get resource description (optional)
256
	 *
257
	 * @return string
258
	 *
259
	 * @since 14.0.0
260
	 */
261
	public function getDescription() {
262
		return $this->share['description'];
263
	}
264
265
	/**
266
	 * get provider ID (e.g. file ID)
267
	 *
268
	 * @return string
269
	 *
270
	 * @since 14.0.0
271
	 */
272
	public function getProviderId() {
273
		return $this->share['providerId'];
274
	}
275
276
	/**
277
	 * get owner UID
278
	 *
279
	 * @return string
280
	 *
281
	 * @since 14.0.0
282
	 */
283
	public function getOwner() {
284
		return $this->share['owner'];
285
	}
286
287
	/**
288
	 * get owner display name
289
	 *
290
	 * @return string
291
	 *
292
	 * @since 14.0.0
293
	 */
294
	public function getOwnerDisplayName() {
295
		return $this->share['ownerDisplayName'];
296
	}
297
298
	/**
299
	 * get UID of the user who sends the share
300
	 *
301
	 * @return string
302
	 *
303
	 * @since 14.0.0
304
	 */
305
	public function getSharedBy() {
306
		return $this->share['sharedBy'];
307
	}
308
309
	/**
310
	 * get display name of the user who sends the share
311
	 *
312
	 * @return string
313
	 *
314
	 * @since 14.0.0
315
	 */
316
	public function getSharedByDisplayName() {
317
		return $this->share['sharedByDisplayName'];
318
	}
319
320
	/**
321
	 * get share type (group or user)
322
	 *
323
	 * @return string
324
	 *
325
	 * @since 14.0.0
326
	 */
327
	public function getShareType() {
328
		return $this->share['shareType'];
329
	}
330
331
	/**
332
	 * get share Secret
333
	 *
334
	 * @return string
335
	 *
336
	 * @since 14.0.0
337
	 */
338
	public function getShareSecret() {
339
		return $this->share['protocol']['options']['sharedSecret'];
340
	}
341
342
	/**
343
	 * get protocol specification
344
	 *
345
	 * @return array
346
	 *
347
	 * @since 14.0.0
348
	 */
349
	public function getProtocol() {
350
		return $this->share['protocol'];
351
	}
352
}
353