Completed
Push — federated-circles ( dba84e...c0d7e5 )
by Maxence
02:36
created

BaseCircle::getName()   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
	/** @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(string $uniqueId) {
96
		$this->uniqueId = $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
	public function getUser() {
136
		return $this->user;
137
	}
138
139
	public function setUser($user) {
140
		$this->user = $user;
141
142
		return $this;
143
	}
144
145
146
	public function setDescription($description) {
147
		$this->description = $description;
148
149
		return $this;
150
	}
151
152
	public function getDescription() {
153
		return $this->description;
154
	}
155
156
157
	public function setType($type) {
158
		$this->type = (int)$type;
159
160
		return $this;
161
	}
162
163
	public function getType() {
164
		return $this->type;
165
	}
166
167
168
	public function setCreation($creation) {
169
		$this->creation = $creation;
170
171
		return $this;
172
	}
173
174
	public function getCreation() {
175
		return $this->creation;
176
	}
177
178
179
	public function setMembers($members) {
180
		$this->members = $members;
181
182
		return $this;
183
	}
184
185
	public function getMembers() {
186
		return $this->members;
187
	}
188
189
190
	public function getRemote() {
191
		return $this->links;
192
	}
193
194
	public function addRemote($link) {
195
		array_push($this->links, $link);
196
	}
197
198
	public function getRemoteFromToken($token) {
199
		foreach ($this->links AS $link) {
200
			if ($link->getToken() === $token) {
201
				return $link;
202
			}
203
		}
204
205
		return null;
206
	}
207
208
	public function getRemoteFromAddressAndId($address, $id) {
209
		foreach ($this->links AS $link) {
210
			if ($link->getAddress() === $address && $link->getUniqueId() === $id) {
211
				return $link;
212
			}
213
		}
214
215
		return null;
216
	}
217
218
}