Completed
Push — master ( 397c2e...5232e6 )
by
unknown
02:26
created

Circle::fromArray()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.439
c 0
b 0
f 0
cc 6
eloc 22
nc 8
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
class Circle implements \JsonSerializable {
30
31
	const CIRCLES_PERSONAL = 1;
32
	const CIRCLES_HIDDEN = 2;
33
	const CIRCLES_PRIVATE = 4;
34
	const CIRCLES_PUBLIC = 8;
35
36
	const CIRCLES_ALL = 15;
37
38
	private $id;
39
	private $name;
40
41
	/** @var Member */
42
	private $owner;
43
44
	/** @var Member */
45
	private $user;
46
	private $description;
47
	private $type;
48
	private $typeString;
49
	private $typeLongString;
50
	private $creation;
51
	private $count;
52
	private $members;
53
	private $info;
54
55
	public function __construct() {
56
57
	}
58
59
60
	public function setId($id) {
61
		$this->id = $id;
62
63
		return $this;
64
	}
65
66
	public function getId() {
67
		return $this->id;
68
	}
69
70
71
	public function setName($name) {
72
		$this->name = $name;
73
74
		return $this;
75
	}
76
77
	public function getName() {
78
		return $this->name;
79
	}
80
81
82
	public function getOwner() {
83
		return $this->owner;
84
	}
85
86
	public function setOwner($owner) {
87
		$this->owner = $owner;
88
	}
89
90
91
	public function getUser() {
92
		return $this->user;
93
	}
94
95
	public function setUser($user) {
96
		$this->user = $user;
97
	}
98
99
100
	public function setDescription($description) {
101
		$this->description = $description;
102
103
		return $this;
104
	}
105
106
	public function getDescription() {
107
		return $this->description;
108
	}
109
110
111
	public function setType($type) {
112
		$this->type = (int)$type;
113
		$this->setTypeString(self::TypeString($type));
114
		$this->setTypeLongString(self::TypeLongString($type));
115
		$this->setInfo($this->getTypeLongString());
116
117
		return $this;
118
	}
119
120
	public function getType() {
121
		return $this->type;
122
	}
123
124
	public function setTypeString($str) {
125
		$this->typeString = $str;
126
127
		return $this;
128
	}
129
130
	public function getTypeString() {
131
		return $this->typeString;
132
	}
133
134
	public function setTypeLongString($str) {
135
		$this->typeLongString = $str;
136
	}
137
138
	public function getTypeLongString() {
139
		return $this->typeLongString;
140
	}
141
142
143
	public function setInfo($str) {
144
		$this->info = $str;
145
	}
146
147
	public function getInfo() {
148
		return $this->info;
149
	}
150
151
152
	public function setCreation($creation) {
153
		$this->creation = $creation;
154
155
		return $this;
156
	}
157
158
	public function getCreation() {
159
		return $this->creation;
160
	}
161
162
163
	public function setCount($count) {
164
		$this->count = $count;
165
166
		return $this;
167
	}
168
169
	public function getCount() {
170
		return $this->count;
171
	}
172
173
	public function setMembers($members) {
174
		$this->members = $members;
175
176
		return $this;
177
	}
178
179
	public function getMembers() {
180
		return $this->members;
181
	}
182
183
184
	public function toString() {
185
		return "toString ?";
186
	}
187
188
	public function jsonSerialize() {
189
		return array(
190
			'id'          => $this->getId(),
191
			'name'        => $this->getName(),
192
			'owner'       => $this->getOwner(),
193
			'user'        => $this->getUser(),
194
			'description' => $this->getDescription(),
195
			'type'        => $this->getTypeString(),
196
			'creation'    => $this->getCreation(),
197
			'count'       => $this->getCount(),
198
			'members'     => $this->getMembers()
199
		);
200
	}
201
202
	public static function fromArray($arr) {
203
		$circle = new Circle();
204
		$circle->setId($arr['id']);
205
206
		$circle->setName($arr['name']);
207
		$circle->setDescription($arr['description']);
208
		$circle->setType($arr['type']);
209
		$circle->setCreation($arr['creation']);
210
		if (key_exists('count', $arr)) {
211
			$circle->setCount($arr['count']);
212
		}
213
214
		if (key_exists('owner', $arr)) {
215
			$owner = new Member();
216
			$owner->setUserId($arr['owner']);
217
			$circle->setOwner($owner);
218
		}
219
220
		if (key_exists('status', $arr)
221
			&& key_exists('level', $arr)
222
			&& key_exists('joined', $arr)
223
		) {
224
			$user = new Member();
225
			$user->setStatus($arr['status']);
226
			$user->setLevel($arr['level']);
227
			$user->setJoined($arr['joined']);
228
			$circle->setUser($user);
229
		}
230
231
		return $circle;
232
	}
233
234
	public static function TypeString($type) {
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
235
		switch ($type) {
236
			case self::CIRCLES_PERSONAL:
237
				return 'Personal';
238
			case self::CIRCLES_HIDDEN:
239
				return 'Hidden';
240
			case self::CIRCLES_PRIVATE:
241
				return 'Private';
242
			case self::CIRCLES_PUBLIC:
243
				return 'Public';
244
			case self::CIRCLES_ALL:
245
				return 'All';
246
		}
247
248
		return 'none';
249
	}
250
251
	public static function TypeLongString($type) {
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
252
		switch ($type) {
253
			case self::CIRCLES_PERSONAL:
254
				return 'Personal Circle';
255
			case self::CIRCLES_HIDDEN:
256
				return 'Hidden Circle';
257
			case self::CIRCLES_PRIVATE:
258
				return 'Private Circle';
259
			case self::CIRCLES_PUBLIC:
260
				return 'Public Circle';
261
			case self::CIRCLES_ALL:
262
				return 'All Circles';
263
		}
264
265
		return 'none';
266
	}
267
268
}
269
270
271