|
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 OCA\Circles\Exceptions\MemberIsNotModeratorException; |
|
30
|
|
|
|
|
31
|
|
|
class Member implements \JsonSerializable { |
|
32
|
|
|
|
|
33
|
|
|
const LEVEL_NONE = 0; |
|
34
|
|
|
const LEVEL_MEMBER = 1; |
|
35
|
|
|
const LEVEL_MODERATOR = 6; |
|
36
|
|
|
const LEVEL_ADMIN = 8; |
|
37
|
|
|
const LEVEL_OWNER = 9; |
|
38
|
|
|
|
|
39
|
|
|
const STATUS_NONMEMBER = 'Unknown'; |
|
40
|
|
|
const STATUS_INVITED = 'Invited'; |
|
41
|
|
|
const STATUS_REQUEST = 'Requesting'; |
|
42
|
|
|
const STATUS_MEMBER = 'Member'; |
|
43
|
|
|
const STATUS_BLOCKED = 'Blocked'; |
|
44
|
|
|
const STATUS_KICKED = 'Kicked'; |
|
45
|
|
|
|
|
46
|
|
|
private $circleid; |
|
47
|
|
|
private $userid; |
|
48
|
|
|
private $level; |
|
49
|
|
|
private $levelString; |
|
50
|
|
|
private $status; |
|
51
|
|
|
private $note; |
|
52
|
|
|
private $joined; |
|
53
|
|
|
|
|
54
|
|
|
public function __construct() { |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
public function setCircleId($circleid) { |
|
59
|
|
|
$this->circleid = (int)$circleid; |
|
60
|
|
|
|
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getCircleId() { |
|
65
|
|
|
return $this->circleid; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
public function setUserId($userid) { |
|
70
|
|
|
$this->userid = $userid; |
|
71
|
|
|
|
|
72
|
|
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getUserId() { |
|
76
|
|
|
return $this->userid; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
public function setLevel($level) { |
|
81
|
|
|
$this->level = (int)$level; |
|
82
|
|
|
$this->setLevelString(self::LevelSring($this->level)); |
|
83
|
|
|
|
|
84
|
|
|
return $this; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getLevel() { |
|
88
|
|
|
return $this->level; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
public function setLevelString($str) { |
|
93
|
|
|
$this->levelString = $str; |
|
94
|
|
|
|
|
95
|
|
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function getLevelString() { |
|
99
|
|
|
return $this->levelString; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
public function setNote($note) { |
|
104
|
|
|
$this->note = $note; |
|
105
|
|
|
|
|
106
|
|
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getNote() { |
|
110
|
|
|
return $this->note; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
public function setStatus($status) { |
|
115
|
|
|
if (is_null($status)) { |
|
116
|
|
|
$this->status = self::STATUS_NONMEMBER; |
|
117
|
|
|
} else { |
|
118
|
|
|
$this->status = $status; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getStatus() { |
|
125
|
|
|
return $this->status; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
public function setJoined($joined) { |
|
130
|
|
|
$this->joined = $joined; |
|
131
|
|
|
|
|
132
|
|
|
return $this; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function getJoined() { |
|
136
|
|
|
return $this->joined; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function isModerator() { |
|
140
|
|
|
if ($this->getLevel() >= self::LEVEL_MODERATOR) { |
|
141
|
|
|
return true; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
throw new MemberIsNotModeratorException(); |
|
145
|
|
|
|
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function jsonSerialize() { |
|
149
|
|
|
return array( |
|
150
|
|
|
'circleid' => $this->getCircleId(), |
|
151
|
|
|
'userid' => $this->getUserId(), |
|
152
|
|
|
'level' => $this->getLevel(), |
|
153
|
|
|
'level_string' => $this->getLevelString(), |
|
154
|
|
|
'status' => $this->getStatus(), |
|
155
|
|
|
'joined' => $this->getJoined() |
|
156
|
|
|
); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
public static function fromArray($arr) { |
|
161
|
|
|
|
|
162
|
|
|
if (!is_array($arr)) { |
|
163
|
|
|
return null; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
$member = new Member(); |
|
167
|
|
|
|
|
168
|
|
|
$member->setCircleId($arr['circle_id']); |
|
169
|
|
|
$member->setUserId($arr['user_id']); |
|
170
|
|
|
$member->setLevel($arr['level']); |
|
171
|
|
|
$member->setStatus($arr['status']); |
|
172
|
|
|
if (key_exists('note', $arr)) { |
|
173
|
|
|
$member->setNote($arr['note']); |
|
174
|
|
|
} |
|
175
|
|
|
if (key_exists('joined', $arr)) { |
|
176
|
|
|
$member->setJoined($arr['joined']); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
return $member; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
public static function LevelSring($level) { |
|
|
|
|
|
|
184
|
|
|
switch ($level) { |
|
185
|
|
|
case self::LEVEL_NONE: |
|
186
|
|
|
return 'Not a member'; |
|
187
|
|
|
case self::LEVEL_MEMBER: |
|
188
|
|
|
return 'Member'; |
|
189
|
|
|
case self::LEVEL_MODERATOR: |
|
190
|
|
|
return 'Moderator'; |
|
191
|
|
|
case self::LEVEL_ADMIN: |
|
192
|
|
|
return 'Admin'; |
|
193
|
|
|
case self::LEVEL_OWNER: |
|
194
|
|
|
return 'Owner'; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
return 'none'; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
|
|
201
|
|
|
public function toString() { |
|
202
|
|
|
return "toString ?"; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
|
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.