|
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\CircleTypeNotValid; |
|
30
|
|
|
|
|
31
|
|
|
class Circle extends BaseCircle implements \JsonSerializable { |
|
32
|
|
|
|
|
33
|
|
|
public function getTypeString() { |
|
34
|
|
|
switch ($this->getType()) { |
|
35
|
|
|
case self::CIRCLES_PERSONAL: |
|
36
|
|
|
return 'Personal'; |
|
37
|
|
|
case self::CIRCLES_HIDDEN: |
|
38
|
|
|
return 'Hidden'; |
|
39
|
|
|
case self::CIRCLES_PRIVATE: |
|
40
|
|
|
return 'Private'; |
|
41
|
|
|
case self::CIRCLES_PUBLIC: |
|
42
|
|
|
return 'Public'; |
|
43
|
|
|
case self::CIRCLES_ALL: |
|
44
|
|
|
return 'All'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return 'none'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getTypeLongString() { |
|
51
|
|
|
return self::typeLongString($this->getType()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function getInfo() { |
|
56
|
|
|
return $this->getTypeLongString(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
public function jsonSerialize() { |
|
61
|
|
|
return array( |
|
62
|
|
|
'id' => $this->getId(), |
|
63
|
|
|
'name' => $this->getName(), |
|
64
|
|
|
'owner' => $this->getOwner(), |
|
65
|
|
|
'user' => $this->getUser(), |
|
66
|
|
|
'description' => $this->getDescription(), |
|
67
|
|
|
'settings' => $this->getSettings(), |
|
68
|
|
|
'type' => $this->getTypeString(), |
|
69
|
|
|
'creation' => $this->getCreation(), |
|
70
|
|
|
'typeString' => $this->getTypeString(), |
|
71
|
|
|
'typeLongString' => $this->getTypeLongString(), |
|
72
|
|
|
'unique_id' => $this->getUniqueId(), |
|
73
|
|
|
'members' => $this->getMembers(), |
|
74
|
|
|
'links' => $this->getRemote() |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
// /** |
|
|
|
|
|
|
79
|
|
|
// * set all infos from an Array. |
|
80
|
|
|
// * |
|
81
|
|
|
// * @param $arr |
|
82
|
|
|
// * |
|
83
|
|
|
// * @return $this |
|
84
|
|
|
// */ |
|
85
|
|
|
// public function fromArray($arr) { |
|
86
|
|
|
// $this->setId($arr['id']); |
|
87
|
|
|
// $this->setName($arr['name']); |
|
88
|
|
|
// $this->setUniqueId($arr['unique_id']); |
|
89
|
|
|
// $this->setDescription($arr['description']); |
|
90
|
|
|
// $this->setType($arr['type']); |
|
91
|
|
|
// $this->setCreation($arr['creation']); |
|
92
|
|
|
//// $this->setOwnerMemberFromArray($arr); |
|
93
|
|
|
//// $this->setUserMemberFromArray($arr); |
|
94
|
|
|
// |
|
95
|
|
|
// return $this; |
|
96
|
|
|
// } |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* set all infos from an Array. |
|
100
|
|
|
* |
|
101
|
|
|
* @param $l10n |
|
102
|
|
|
* @param $arr |
|
103
|
|
|
* |
|
104
|
|
|
* @return $this |
|
105
|
|
|
*/ |
|
106
|
|
|
public static function fromArray2($l10n, $arr) { |
|
107
|
|
|
$circle = new Circle($l10n); |
|
108
|
|
|
|
|
109
|
|
|
$circle->setId($arr['id']); |
|
110
|
|
|
$circle->setName($arr['name']); |
|
111
|
|
|
$circle->setUniqueId($arr['unique_id']); |
|
112
|
|
|
$circle->setDescription($arr['description']); |
|
113
|
|
|
if (key_exists('settings', $arr)) { |
|
114
|
|
|
$circle->setSettings($arr['settings']); |
|
115
|
|
|
} |
|
116
|
|
|
$circle->setType($arr['type']); |
|
117
|
|
|
$circle->setCreation($arr['creation']); |
|
118
|
|
|
|
|
119
|
|
|
if (key_exists('user', $arr)) { |
|
120
|
|
|
$circle->setUser(Member::fromArray2($l10n, $arr['user'])); |
|
121
|
|
|
} |
|
122
|
|
|
if (key_exists('owner', $arr)) { |
|
123
|
|
|
$circle->setOwner(Member::fromArray2($l10n, $arr['owner'])); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return $circle; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
public static function fromJSON($l10n, $json) { |
|
131
|
|
|
return self::fromArray2($l10n, json_decode($json, true)); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
// |
|
|
|
|
|
|
136
|
|
|
// |
|
137
|
|
|
// /** |
|
138
|
|
|
// * set User Infos from Array |
|
139
|
|
|
// * |
|
140
|
|
|
// * @param $array |
|
141
|
|
|
// */ |
|
142
|
|
|
// // TODO rewrite the function based of setOwnerMemberFromArray() |
|
143
|
|
|
// private function setUserMemberFromArray($array) { |
|
144
|
|
|
// if (key_exists('status', $array) |
|
145
|
|
|
// && key_exists('level', $array) |
|
146
|
|
|
// && key_exists('joined', $array) |
|
147
|
|
|
// ) { |
|
148
|
|
|
// $user = new Member($this->l10n); |
|
149
|
|
|
// $user->setStatus($array['status']); |
|
150
|
|
|
// $user->setLevel($array['level']); |
|
151
|
|
|
// $user->setJoined($array['joined']); |
|
152
|
|
|
// $this->setUser($user); |
|
153
|
|
|
// } |
|
154
|
|
|
// } |
|
155
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @throws CircleTypeNotValid |
|
159
|
|
|
*/ |
|
160
|
|
|
public function cantBePersonal() { |
|
161
|
|
|
if ($this->getType() === self::CIRCLES_PERSONAL) { |
|
162
|
|
|
throw new CircleTypeNotValid( |
|
163
|
|
|
$this->l10n->t("This option is not available for personal circles") |
|
164
|
|
|
); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param $type |
|
171
|
|
|
* |
|
172
|
|
|
* @return string |
|
173
|
|
|
*/ |
|
174
|
|
|
public static function typeLongString($type) { |
|
175
|
|
|
switch ($type) { |
|
176
|
|
|
case self::CIRCLES_PERSONAL: |
|
177
|
|
|
return 'Personal circle'; |
|
178
|
|
|
case self::CIRCLES_HIDDEN: |
|
179
|
|
|
return 'Hidden circle'; |
|
180
|
|
|
case self::CIRCLES_PRIVATE: |
|
181
|
|
|
return 'Private circle'; |
|
182
|
|
|
case self::CIRCLES_PUBLIC: |
|
183
|
|
|
return 'Public circle'; |
|
184
|
|
|
case self::CIRCLES_ALL: |
|
185
|
|
|
return 'All circles'; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
return 'none'; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.