1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Access collection class |
5
|
|
|
* |
6
|
|
|
* @package Elgg.Core |
7
|
|
|
* @subpackage Core |
8
|
|
|
* |
9
|
|
|
* @property-read int $id The unique identifier (read-only) |
10
|
|
|
* @property int $owner_guid GUID of the owner |
11
|
|
|
* @property string $name Name of the collection |
12
|
|
|
*/ |
13
|
|
|
class ElggAccessCollection extends ElggData { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Create an access collection object |
17
|
|
|
* |
18
|
|
|
* @param stdClass $row Database row |
19
|
|
|
* @throws InvalidArgumentException |
20
|
|
|
*/ |
21
|
|
|
public function __construct(stdClass $row = null) { |
22
|
|
|
$this->initializeAttributes(); |
23
|
|
|
|
24
|
|
|
foreach ((array) $row as $key => $value) { |
25
|
|
|
$this->attributes[$key] = $value; |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Initialize the attributes array |
31
|
|
|
* |
32
|
|
|
* @see ElggData::initializeAttributes() |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
protected function initializeAttributes() { |
36
|
|
|
parent::initializeAttributes(); |
37
|
|
|
|
38
|
|
|
$this->attributes['id'] = null; |
39
|
|
|
$this->attributes['owner_guid'] = null; |
40
|
|
|
$this->attributes['name'] = null; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Set an attribute |
45
|
|
|
* |
46
|
|
|
* @param string $name Name |
47
|
|
|
* @param mixed $value Value |
48
|
|
|
* @return void |
49
|
|
|
* @throws RuntimeException |
50
|
|
|
*/ |
51
|
|
|
public function __set($name, $value) { |
52
|
|
|
if (in_array($name, ['id', 'owner_guid'])) { |
53
|
|
|
throw new RuntimeException("$name can not be set at runtime"); |
54
|
|
|
} |
55
|
|
|
$this->attributes[$name] = $value; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get an attribute |
60
|
|
|
* |
61
|
|
|
* @param string $name Name |
62
|
|
|
* @return mixed |
63
|
|
|
*/ |
64
|
|
|
public function __get($name) { |
65
|
|
|
if (array_key_exists($name, $this->attributes)) { |
66
|
|
|
return $this->attributes[$name]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function save() { |
76
|
|
|
if ($this->id > 0) { |
77
|
|
|
return _elgg_services()->accessCollections->rename($this->id, $this->name); |
|
|
|
|
78
|
|
|
} else { |
79
|
|
|
return _elgg_services()->accessCollections->create($this->name, $this->owner_guid); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function delete() { |
87
|
|
|
return _elgg_services()->accessCollections->delete($this->id); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Check if user can this collection |
92
|
|
|
* |
93
|
|
|
* @param int $user_guid GUID of the user |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
|
|
public function canEdit($user_guid = null) { |
97
|
|
|
return _elgg_services()->accessCollections->canEdit($this->id, $user_guid); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns members of the access collection |
102
|
|
|
* |
103
|
|
|
* @param array $options ege options |
104
|
|
|
* @return ElggEntity|int|false |
105
|
|
|
*/ |
106
|
|
|
public function getMembers(array $options = []) { |
107
|
|
|
return _elgg_services()->accessCollections->getMembers($this->id, $options); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Checks if user is already in access collection |
112
|
|
|
* |
113
|
|
|
* @param int $member_guid GUID of the user |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
|
|
public function hasMember($member_guid = 0) { |
117
|
|
|
return _elgg_services()->accessCollections->hasUser($member_guid, $this->id); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Adds a new member to access collection |
122
|
|
|
* |
123
|
|
|
* @param int $member_guid GUID of the user |
124
|
|
|
* @return bool |
125
|
|
|
*/ |
126
|
|
|
public function addMember($member_guid = 0) { |
127
|
|
|
return _elgg_services()->accessCollections->addUser($member_guid, $this->id); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Removes a user from access collection |
132
|
|
|
* |
133
|
|
|
* @param int $member_guid GUID of the user |
134
|
|
|
* @return bool |
135
|
|
|
*/ |
136
|
|
|
public function removeMember($member_guid = 0) { |
137
|
|
|
return _elgg_services()->accessCollections->removeUser($member_guid, $this->id); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* {@inheritdoc} |
142
|
|
|
*/ |
143
|
|
|
public function getURL() { |
144
|
|
|
$type = $this->getType(); |
145
|
|
|
$params = [ |
146
|
|
|
'access_collection' => $this, |
147
|
|
|
]; |
148
|
|
|
$url = _elgg_services()->hooks->trigger('access_collection:url', $type, $params, $url); |
|
|
|
|
149
|
|
|
return elgg_normalize_url($url); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* {@inheritdoc} |
154
|
|
|
*/ |
155
|
|
|
public function toObject() { |
156
|
|
|
$object = new stdClass(); |
157
|
|
|
$object->type = $this->getType(); |
158
|
|
|
$object->subtype = $this->getSubtype(); |
159
|
|
|
$object->id = $this->id; |
160
|
|
|
$object->owner_guid = $this->owner_guid; |
161
|
|
|
$object->name = $this->name; |
162
|
|
|
|
163
|
|
|
$params = [ |
164
|
|
|
'access_collection' => $this, |
165
|
|
|
]; |
166
|
|
|
return _elgg_services()->hooks->trigger('to:object', 'access_collection', $params, $object); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* {@inheritdoc} |
171
|
|
|
*/ |
172
|
|
|
public function getSystemLogID() { |
173
|
|
|
return $this->id; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* {@inheritdoc} |
178
|
|
|
*/ |
179
|
|
|
public function getObjectFromID($id) { |
180
|
|
|
return _elgg_services()->accessCollections->get($id); |
|
|
|
|
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* {@inheritdoc} |
185
|
|
|
*/ |
186
|
|
|
public function getType() { |
187
|
|
|
return 'access_collection'; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* {@inheritdoc} |
192
|
|
|
*/ |
193
|
|
|
public function getSubtype() { |
194
|
|
|
return $this->name; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
} |
198
|
|
|
|