Completed
Push — master ( fff755...8f8f7b )
by Maxence
03:48
created

BaseCircle::getUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Model;
28
29
use OC\L10N\L10N;
30
31
class BaseCircle {
32
33
34
	const CIRCLES_PERSONAL = 1;
35
	const CIRCLES_HIDDEN = 2;
36
	const CIRCLES_PRIVATE = 4;
37
	const CIRCLES_PUBLIC = 8;
38
39
	const CIRCLES_ALL = 15;
40
41
	/** @var int */
42
	private $id;
43
44
	/** @var L10N */
45
	protected $l10n;
46
47
	/** @var string */
48
	private $uniqueId;
49
50
	/** @var string */
51
	private $name;
52
53
	/** @var Member */
54
	private $owner;
55
56
	/** @var Member */
57
	private $user;
58
59
	/** @var string */
60
	private $description;
61
62
	/** @var int */
63
	private $type;
64
65
	/** @var string */
66
	private $creation;
67
68
	/** @var Member[] */
69
	private $members;
70
71
	/** @var FederatedLink[] */
72
	private $links;
73
74
	public function __construct($l10n, $type = -1, $name = '') {
75
		$this->l10n = $l10n;
76
77
		if ($type > -1) {
78
			$this->type = $type;
79
		}
80
		if ($name !== '') {
81
			$this->name = $name;
82
		}
83
	}
84
85
86
	public function setId($id) {
87
		$this->id = $id;
88
89
		return $this;
90
	}
91
92
	public function getId() {
93
		return $this->id;
94
	}
95
96
97
	/**
98
	 * @param string $uniqueId
99
	 *
100
	 * @return $this
101
	 */
102
	public function setUniqueId($uniqueId) {
103
		$this->uniqueId = (string)$uniqueId;
104
105
		return $this;
106
	}
107
108
	/**
109
	 * @return string
110
	 */
111
	public function getUniqueId() {
112
		return $this->uniqueId;
113
	}
114
115
	public function generateUniqueId() {
116
		$uniqueId = bin2hex(openssl_random_pseudo_bytes(24));
117
		$this->setUniqueId($uniqueId);
118
	}
119
120
	public function setName($name) {
121
		$this->name = $name;
122
123
		return $this;
124
	}
125
126
	public function getName() {
127
		return $this->name;
128
	}
129
130
131
	public function getOwner() {
132
		return $this->owner;
133
	}
134
135
	public function setOwner($owner) {
136
		$this->owner = $owner;
137
138
		return $this;
139
	}
140
141
142
	/**
143
	 * @return Member
144
	 */
145
	public function getUser() {
146
		return $this->user;
147
	}
148
149
	public function setUser($user) {
150
		$this->user = $user;
151
152
		return $this;
153
	}
154
155
156
	public function setDescription($description) {
157
		$this->description = $description;
158
159
		return $this;
160
	}
161
162
	public function getDescription() {
163
		return $this->description;
164
	}
165
166
167
	public function setType($type) {
168
		$this->type = self::typeInt($type);
169
170
		return $this;
171
	}
172
173
	public function getType() {
174
		return $this->type;
175
	}
176
177
178
	public function setCreation($creation) {
179
		$this->creation = $creation;
180
181
		return $this;
182
	}
183
184
	public function getCreation() {
185
		return $this->creation;
186
	}
187
188
189
	public function setMembers($members) {
190
		$this->members = $members;
191
192
		return $this;
193
	}
194
195
	public function getMembers() {
196
		return $this->members;
197
	}
198
199
200
	public function getRemote() {
201
		return $this->links;
202
	}
203
204
	public function addRemote($link) {
205
		array_push($this->links, $link);
206
	}
207
208
	public function getRemoteFromToken($token) {
209
		foreach ($this->links AS $link) {
210
			if ($link->getToken() === $token) {
211
				return $link;
212
			}
213
		}
214
215
		return null;
216
	}
217
218
	public function getRemoteFromAddressAndId($address, $id) {
219
		foreach ($this->links AS $link) {
220
			if ($link->getAddress() === $address && $link->getUniqueId() === $id) {
221
				return $link;
222
			}
223
		}
224
225
		return null;
226
	}
227
228
229
	public static function typeInt($type) {
230
231
		if (is_int($type)) {
232
			return $type;
233
		}
234
235 View Code Duplication
		switch ($type) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
236
			case 'Personal':
237
				return self::CIRCLES_PERSONAL;
238
			case 'Private':
239
				return self::CIRCLES_PRIVATE;
240
			case 'Hidden':
241
				return self::CIRCLES_HIDDEN;
242
			case 'Public':
243
				return self::CIRCLES_PUBLIC;
244
		}
245
246
		return 0;
247
	}
248
}