Completed
Push — testscrut1 ( 5e8804...78769b )
by Maxence
02:27
created

Circle::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
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
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 $members;
52
	private $info;
53
54
	public function __construct() {
55
	}
56
57
58
	public function setId($id) {
59
		$this->id = $id;
60
61
		return $this;
62
	}
63
64
	public function getId() {
65
		return $this->id;
66
	}
67
68
69
	public function setName($name) {
70
		$this->name = $name;
71
72
		return $this;
73
	}
74
75
	public function getName() {
76
		return $this->name;
77
	}
78
79
80
	public function getOwner() {
81
		return $this->owner;
82
	}
83
84
	public function setOwner($owner) {
85
		$this->owner = $owner;
86
	}
87
88
89
	public function getUser() {
90
		return $this->user;
91
	}
92
93
	public function setUser($user) {
94
		$this->user = $user;
95
	}
96
97
98
	public function setDescription($description) {
99
		$this->description = $description;
100
101
		return $this;
102
	}
103
104
	public function getDescription() {
105
		return $this->description;
106
	}
107
108
109
	public function setType($type) {
110
		$this->type = (int)$type;
111
		$this->setTypeString(self::TypeString($type));
112
		$this->setTypeLongString(self::TypeLongString($type));
113
		$this->setInfo($this->getTypeLongString());
114
115
		return $this;
116
	}
117
118
	public function getType() {
119
		return $this->type;
120
	}
121
122
	public function setTypeString($str) {
123
		$this->typeString = $str;
124
125
		return $this;
126
	}
127
128
	public function getTypeString() {
129
		return $this->typeString;
130
	}
131
132
	public function setTypeLongString($str) {
133
		$this->typeLongString = $str;
134
	}
135
136
	public function getTypeLongString() {
137
		return $this->typeLongString;
138
	}
139
140
141
	public function setInfo($str) {
142
		$this->info = $str;
143
	}
144
145
	public function getInfo() {
146
		return $this->info;
147
	}
148
149
150
	public function setCreation($creation) {
151
		$this->creation = $creation;
152
153
		return $this;
154
	}
155
156
	public function getCreation() {
157
		return $this->creation;
158
	}
159
160
161
	public function setMembers($members) {
162
		$this->members = $members;
163
164
		return $this;
165
	}
166
167
	public function getMembers() {
168
		return $this->members;
169
	}
170
171
172
	public function jsonSerialize() {
173
		return array(
174
			'id'          => $this->getId(),
175
			'name'        => $this->getName(),
176
			'owner'       => $this->getOwner(),
177
			'user'        => $this->getUser(),
178
			'description' => $this->getDescription(),
179
			'type'        => $this->getTypeString(),
180
			'creation'    => $this->getCreation(),
181
			'members'     => $this->getMembers()
182
		);
183
	}
184
185
	/**
186
	 * set all infos from an Array.
187
	 *
188
	 * @param $arr
189
	 *
190
	 * @return $this
191
	 */
192
	public function fromArray($arr) {
193
		$this->setId($arr['id']);
194
		$this->setName($arr['name']);
195
		$this->setDescription($arr['description']);
196
		$this->setType($arr['type']);
197
		$this->setCreation($arr['creation']);
198
199
		$this->setOwnerMemberFromArray($arr);
200
		$this->setUserMemberFromArray($arr);
201
202
		return $this;
203
	}
204
205
206
	/**
207
	 * set Owner Infos from Array
208
	 *
209
	 * @param $array
210
	 */
211
	private function setOwnerMemberFromArray($array) {
212
		if (key_exists('owner', $array)) {
213
			$owner = new Member();
214
			$owner->setUserId($array['owner']);
215
			$this->setOwner($owner);
216
		}
217
	}
218
219
220
	/**
221
	 * set User Infos from Array
222
	 *
223
	 * @param $array
224
	 */
225
	private function setUserMemberFromArray($array) {
226
		if (key_exists('status', $array)
227
			&& key_exists('level', $array)
228
			&& key_exists('joined', $array)
229
		) {
230
			$user = new Member();
231
			$user->setStatus($array['status']);
232
			$user->setLevel($array['level']);
233
			$user->setJoined($array['joined']);
234
			$this->setUser($user);
235
		}
236
	}
237
238
239
	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...
240
		switch ($type) {
241
			case self::CIRCLES_PERSONAL:
242
				return 'Personal';
243
			case self::CIRCLES_HIDDEN:
244
				return 'Hidden';
245
			case self::CIRCLES_PRIVATE:
246
				return 'Private';
247
			case self::CIRCLES_PUBLIC:
248
				return 'Public';
249
			case self::CIRCLES_ALL:
250
				return 'All';
251
		}
252
253
		return 'none';
254
	}
255
256
	/**
257
	 * @param $type
258
	 *
259
	 * @return string
260
	 */
261
	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...
262
		switch ($type) {
263
			case self::CIRCLES_PERSONAL:
264
				return 'Personal Circle';
265
			case self::CIRCLES_HIDDEN:
266
				return 'Hidden Circle';
267
			case self::CIRCLES_PRIVATE:
268
				return 'Private Circle';
269
			case self::CIRCLES_PUBLIC:
270
				return 'Public Circle';
271
			case self::CIRCLES_ALL:
272
				return 'All Circles';
273
		}
274
275
		return 'none';
276
	}
277
278
}
279
280
281