Completed
Pull Request — master (#72)
by Maxence
06:31
created

BaseCircle::setUniqueId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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