|
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 toString() { |
|
173
|
|
|
return "toString ?"; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function jsonSerialize() { |
|
177
|
|
|
return array( |
|
178
|
|
|
'id' => $this->getId(), |
|
179
|
|
|
'name' => $this->getName(), |
|
180
|
|
|
'owner' => $this->getOwner(), |
|
181
|
|
|
'user' => $this->getUser(), |
|
182
|
|
|
'description' => $this->getDescription(), |
|
183
|
|
|
'type' => $this->getTypeString(), |
|
184
|
|
|
'creation' => $this->getCreation(), |
|
185
|
|
|
'members' => $this->getMembers() |
|
186
|
|
|
); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* set all infos from an Array. |
|
191
|
|
|
* |
|
192
|
|
|
* @param $arr |
|
193
|
|
|
* |
|
194
|
|
|
* @return $this |
|
195
|
|
|
*/ |
|
196
|
|
|
public function fromArray($arr) { |
|
197
|
|
|
$this->setId($arr['id']); |
|
198
|
|
|
$this->setName($arr['name']); |
|
199
|
|
|
$this->setDescription($arr['description']); |
|
200
|
|
|
$this->setType($arr['type']); |
|
201
|
|
|
$this->setCreation($arr['creation']); |
|
202
|
|
|
|
|
203
|
|
|
$this->setOwnerMemberFromArray($arr); |
|
204
|
|
|
$this->setUserMemberFromArray($arr); |
|
205
|
|
|
|
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* set Owner Infos from Array |
|
212
|
|
|
* |
|
213
|
|
|
* @param $array |
|
214
|
|
|
*/ |
|
215
|
|
|
private function setOwnerMemberFromArray($array) { |
|
216
|
|
|
if (key_exists('owner', $array)) { |
|
217
|
|
|
$owner = new Member(); |
|
218
|
|
|
$owner->setUserId($array['owner']); |
|
219
|
|
|
$this->setOwner($owner); |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* set User Infos from Array |
|
226
|
|
|
* |
|
227
|
|
|
* @param $array |
|
228
|
|
|
*/ |
|
229
|
|
|
private function setUserMemberFromArray($array) { |
|
230
|
|
|
if (key_exists('status', $array) |
|
231
|
|
|
&& key_exists('level', $array) |
|
232
|
|
|
&& key_exists('joined', $array) |
|
233
|
|
|
) { |
|
234
|
|
|
$user = new Member(); |
|
235
|
|
|
$user->setStatus($array['status']); |
|
236
|
|
|
$user->setLevel($array['level']); |
|
237
|
|
|
$user->setJoined($array['joined']); |
|
238
|
|
|
$this->setUser($user); |
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
|
|
243
|
|
|
public static function TypeString($type) { |
|
|
|
|
|
|
244
|
|
|
switch ($type) { |
|
245
|
|
|
case self::CIRCLES_PERSONAL: |
|
246
|
|
|
return 'Personal'; |
|
247
|
|
|
case self::CIRCLES_HIDDEN: |
|
248
|
|
|
return 'Hidden'; |
|
249
|
|
|
case self::CIRCLES_PRIVATE: |
|
250
|
|
|
return 'Private'; |
|
251
|
|
|
case self::CIRCLES_PUBLIC: |
|
252
|
|
|
return 'Public'; |
|
253
|
|
|
case self::CIRCLES_ALL: |
|
254
|
|
|
return 'All'; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
return 'none'; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @param $type |
|
262
|
|
|
* |
|
263
|
|
|
* @return string |
|
264
|
|
|
*/ |
|
265
|
|
|
public static function TypeLongString($type) { |
|
|
|
|
|
|
266
|
|
|
switch ($type) { |
|
267
|
|
|
case self::CIRCLES_PERSONAL: |
|
268
|
|
|
return 'Personal Circle'; |
|
269
|
|
|
case self::CIRCLES_HIDDEN: |
|
270
|
|
|
return 'Hidden Circle'; |
|
271
|
|
|
case self::CIRCLES_PRIVATE: |
|
272
|
|
|
return 'Private Circle'; |
|
273
|
|
|
case self::CIRCLES_PUBLIC: |
|
274
|
|
|
return 'Public Circle'; |
|
275
|
|
|
case self::CIRCLES_ALL: |
|
276
|
|
|
return 'All Circles'; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
return 'none'; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
|
|
285
|
|
|
|
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.