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($circleId = -1, $userId = '') { |
63
|
|
|
if ($circleId > -1) { |
64
|
|
|
$this->setCircleId($circleId); |
65
|
|
|
} |
66
|
|
|
if ($userId !== '') { |
67
|
|
|
$this->setUserId($userId); |
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
|
|
|
/** |
146
|
|
|
* @param array $arr |
147
|
|
|
* |
148
|
|
|
* @return null |
|
|
|
|
149
|
|
|
*/ |
150
|
|
|
public function fromArray($arr) { |
151
|
|
|
$this->setCircleId($arr['circle_id']); |
152
|
|
|
$this->setUserId($arr['user_id']); |
153
|
|
|
$this->setLevel($arr['level']); |
154
|
|
|
$this->setStatus($arr['status']); |
155
|
|
|
if (key_exists('note', $arr)) { |
156
|
|
|
$this->setNote($arr['note']); |
157
|
|
|
} |
158
|
|
|
if (key_exists('joined', $arr)) { |
159
|
|
|
$this->setJoined($arr['joined']); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.