|
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 extends BaseCircle 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
|
|
|
public function getTypeString() { |
|
39
|
|
|
return self::typeString($this->getType()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getTypeLongString() { |
|
43
|
|
|
return self::typeLongString($this->getType()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
public function getInfo() { |
|
48
|
|
|
return $this->getTypeLongString(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function jsonSerialize() { |
|
52
|
|
|
return array( |
|
53
|
|
|
'id' => $this->getId(), |
|
54
|
|
|
'name' => $this->getName(), |
|
55
|
|
|
'owner' => $this->getOwner(), |
|
56
|
|
|
'user' => $this->getUser(), |
|
57
|
|
|
'description' => $this->getDescription(), |
|
58
|
|
|
'type' => $this->getTypeString(), |
|
59
|
|
|
'creation' => $this->getCreation(), |
|
60
|
|
|
'members' => $this->getMembers() |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* set all infos from an Array. |
|
66
|
|
|
* |
|
67
|
|
|
* @param $arr |
|
68
|
|
|
* |
|
69
|
|
|
* @return $this |
|
70
|
|
|
*/ |
|
71
|
|
|
public function fromArray($arr) { |
|
72
|
|
|
$this->setId($arr['id']); |
|
73
|
|
|
$this->setName($arr['name']); |
|
74
|
|
|
$this->setDescription($arr['description']); |
|
75
|
|
|
$this->setType($arr['type']); |
|
76
|
|
|
$this->setCreation($arr['creation']); |
|
77
|
|
|
|
|
78
|
|
|
$this->setOwnerMemberFromArray($arr); |
|
79
|
|
|
$this->setUserMemberFromArray($arr); |
|
80
|
|
|
|
|
81
|
|
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* set Owner Infos from Array |
|
87
|
|
|
* |
|
88
|
|
|
* @param $array |
|
89
|
|
|
*/ |
|
90
|
|
|
private function setOwnerMemberFromArray($array) { |
|
91
|
|
|
if (key_exists('owner', $array)) { |
|
92
|
|
|
$owner = new Member(); |
|
93
|
|
|
$owner->setUserId($array['owner']); |
|
94
|
|
|
$this->setOwner($owner); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* set User Infos from Array |
|
101
|
|
|
* |
|
102
|
|
|
* @param $array |
|
103
|
|
|
*/ |
|
104
|
|
|
private function setUserMemberFromArray($array) { |
|
105
|
|
|
if (key_exists('status', $array) |
|
106
|
|
|
&& key_exists('level', $array) |
|
107
|
|
|
&& key_exists('joined', $array) |
|
108
|
|
|
) { |
|
109
|
|
|
$user = new Member(); |
|
110
|
|
|
$user->setStatus($array['status']); |
|
111
|
|
|
$user->setLevel($array['level']); |
|
112
|
|
|
$user->setJoined($array['joined']); |
|
113
|
|
|
$this->setUser($user); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
public static function typeString($type) { |
|
119
|
|
|
switch ($type) { |
|
120
|
|
|
case self::CIRCLES_PERSONAL: |
|
121
|
|
|
return 'Personal'; |
|
122
|
|
|
case self::CIRCLES_HIDDEN: |
|
123
|
|
|
return 'Hidden'; |
|
124
|
|
|
case self::CIRCLES_PRIVATE: |
|
125
|
|
|
return 'Private'; |
|
126
|
|
|
case self::CIRCLES_PUBLIC: |
|
127
|
|
|
return 'Public'; |
|
128
|
|
|
case self::CIRCLES_ALL: |
|
129
|
|
|
return 'All'; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
return 'none'; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param $type |
|
137
|
|
|
* |
|
138
|
|
|
* @return string |
|
139
|
|
|
*/ |
|
140
|
|
|
public static function typeLongString($type) { |
|
141
|
|
|
switch ($type) { |
|
142
|
|
|
case self::CIRCLES_PERSONAL: |
|
143
|
|
|
return 'Personal Circle'; |
|
144
|
|
|
case self::CIRCLES_HIDDEN: |
|
145
|
|
|
return 'Hidden Circle'; |
|
146
|
|
|
case self::CIRCLES_PRIVATE: |
|
147
|
|
|
return 'Private Circle'; |
|
148
|
|
|
case self::CIRCLES_PUBLIC: |
|
149
|
|
|
return 'Public Circle'; |
|
150
|
|
|
case self::CIRCLES_ALL: |
|
151
|
|
|
return 'All Circles'; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
return 'none'; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
|