Completed
Push — some-scrutinizing ( 18fbfb...d3de44 )
by Maxence
03:16
created

BaseMember::isLevel()   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 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 BaseMember {
30
31
	const LEVEL_NONE = 0;
32
	const LEVEL_MEMBER = 1;
33
	const LEVEL_MODERATOR = 6;
34
	const LEVEL_ADMIN = 8;
35
	const LEVEL_OWNER = 9;
36
37
	const STATUS_NONMEMBER = 'Unknown';
38
	const STATUS_INVITED = 'Invited';
39
	const STATUS_REQUEST = 'Requesting';
40
	const STATUS_MEMBER = 'Member';
41
	const STATUS_BLOCKED = 'Blocked';
42
	const STATUS_KICKED = 'Kicked';
43
44
	/** @var int */
45
	private $circleId;
46
47
	/** @var string */
48
	private $userId;
49
50
	/** @var int */
51
	private $level;
52
53
	/** @var string */
54
	private $status;
55
56
	/** @var string */
57
	private $note;
58
59
	/** @var string */
60
	private $joined;
61
62
	public function __construct($userId = '', $circleId = -1) {
63
		if ($userId !== '') {
64
			$this->setUserId($userId);
65
		}
66
		if ($circleId > -1) {
67
			$this->setCircleId($circleId);
68
		}
69
		$this->setLevel(Member::LEVEL_NONE);
70
		$this->setStatus(Member::STATUS_NONMEMBER);
71
72
	}
73
74
75
	public function setCircleId($circleId) {
76
		$this->circleId = (int)$circleId;
77
78
		return $this;
79
	}
80
81
	public function getCircleId() {
82
		return $this->circleId;
83
	}
84
85
86
	public function setUserId($userId) {
87
		$this->userId = $userId;
88
89
		return $this;
90
	}
91
92
	public function getUserId() {
93
		return $this->userId;
94
	}
95
96
97
	public function setLevel($level) {
98
		$this->level = (int)$level;
99
100
		return $this;
101
	}
102
103
	public function getLevel() {
104
		return $this->level;
105
	}
106
107
108
	public function setNote($note) {
109
		$this->note = $note;
110
111
		return $this;
112
	}
113
114
	public function getNote() {
115
		return $this->note;
116
	}
117
118
119
	public function setStatus($status) {
120
		if (is_null($status)) {
121
			$this->status = self::STATUS_NONMEMBER;
122
		} else {
123
			$this->status = $status;
124
		}
125
126
		return $this;
127
	}
128
129
	public function getStatus() {
130
		return $this->status;
131
	}
132
133
134
	public function setJoined($joined) {
135
		$this->joined = $joined;
136
137
		return $this;
138
	}
139
140
	public function getJoined() {
141
		return $this->joined;
142
	}
143
144
145
	public function isLevel($level) {
146
		return ($this->getLevel() >= $level);
147
	}
148
149
	protected function setAsAMember($level = 1) {
150
		$this->setStatus(Member::STATUS_MEMBER);
151
		$this->setLevel($level);
152
	}
153
154
155
	/**
156
	 * @param array $arr
157
	 *
158
	 * @return BaseMember
159
	 */
160
	public function fromArray($arr) {
161
		$this->setCircleId($arr['circle_id']);
162
		$this->setUserId($arr['user_id']);
163
		$this->setLevel($arr['level']);
164
		$this->setStatus($arr['status']);
165
		if (key_exists('note', $arr)) {
166
			$this->setNote($arr['note']);
167
		}
168
		if (key_exists('joined', $arr)) {
169
			$this->setJoined($arr['joined']);
170
		}
171
172
		return $this;
173
	}
174
175
176
}
177