Elgg  Version 3.0
ElggAccessCollection.php
Go to the documentation of this file.
1 <?php
2 
14 
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 
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  $this->attributes['subtype'] = null;
42  }
43 
52  public function __set($name, $value) {
53  if (in_array($name, ['id', 'owner_guid', 'subtype'])) {
54  throw new RuntimeException("$name can not be set at runtime");
55  }
56  $this->attributes[$name] = $value;
57  }
58 
65  public function __get($name) {
66  if (array_key_exists($name, $this->attributes)) {
67  return $this->attributes[$name];
68  }
69 
70  return null;
71  }
72 
77  public function getOwnerEntity() {
78  return _elgg_services()->entityTable->get($this->owner_guid);
79  }
80 
85  public function getDisplayName() {
86 
87  $filter = function($name = null) {
88  if (!isset($name)) {
89  $name = _elgg_services()->translator->translate('access:limited:label');
90  }
91  $params = [
92  'access_collection' => $this,
93  ];
94  return _elgg_services()->hooks->trigger('access_collection:name', $this->getType(), $params, $name);
95  };
96 
97  $user = _elgg_services()->session->getLoggedInUser();
98  $owner = $this->getOwnerEntity();
99  if (!$user || !$owner) {
100  // User is not logged in or does not access to the owner entity:
101  // return default 'Limited' label
102  return $filter();
103  }
104 
105  if ($user->isAdmin() || $owner->guid == $user->guid) {
106  return $filter($this->name);
107  }
108 
109  return $filter();
110  }
111 
115  public function save() {
116  if ($this->id > 0) {
117  return _elgg_services()->accessCollections->rename($this->id, $this->name);
118  } else {
119  return _elgg_services()->accessCollections->create($this->name, $this->owner_guid);
120  }
121  }
122 
126  public function delete() {
127  return _elgg_services()->accessCollections->delete($this->id);
128  }
129 
136  public function canEdit($user_guid = null) {
137  return _elgg_services()->accessCollections->canEdit($this->id, $user_guid);
138  }
139 
146  public function getMembers(array $options = []) {
147  return _elgg_services()->accessCollections->getMembers($this->id, $options);
148  }
149 
156  public function hasMember($member_guid = 0) {
157  return _elgg_services()->accessCollections->hasUser($member_guid, $this->id);
158  }
159 
166  public function addMember($member_guid = 0) {
167  return _elgg_services()->accessCollections->addUser($member_guid, $this->id);
168  }
169 
176  public function removeMember($member_guid = 0) {
177  return _elgg_services()->accessCollections->removeUser($member_guid, $this->id);
178  }
179 
183  public function getURL() {
184  $type = $this->getType();
185  $params = [
186  'access_collection' => $this,
187  ];
188  $url = _elgg_services()->hooks->trigger('access_collection:url', $type, $params);
189  return elgg_normalize_url($url);
190  }
191 
195  public function toObject(array $params = []) {
196  $object = new \Elgg\Export\AccessCollection();
197  $object->type = $this->getType();
198  $object->subtype = $this->getSubtype();
199  $object->id = $this->id;
200  $object->owner_guid = $this->owner_guid;
201  $object->name = $this->name;
202 
203  $params['access_collection'] = $this;
204 
205  return _elgg_services()->hooks->trigger('to:object', 'access_collection', $params, $object);
206  }
207 
211  public function getSystemLogID() {
212  return $this->id;
213  }
214 
218  public function getObjectFromID($id) {
219  return _elgg_services()->accessCollections->get($id);
220  }
221 
225  public function getType() {
226  return 'access_collection';
227  }
228 
232  public function getSubtype() {
233  if (isset($this->subtype)) {
234  return $this->subtype;
235  }
236 
237  return $this->name;
238  }
239 
240 }
removeMember($member_guid=0)
Removes a user from access collection.
if(!$item instanceof ElggRiverItem) $object
Definition: responses.php:23
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$params
Saves global plugin settings.
Definition: save.php:13
elgg_normalize_url($url)
Definition: output.php:186
canEdit($user_guid=null)
Check if user can this collection.
toObject(array $params=[])
{}
$subtype
Definition: delete.php:22
$type
Definition: delete.php:21
$options
Elgg admin footer.
Definition: footer.php:6
getDisplayName()
Get readable access level name for this collection.
__set($name, $value)
Set an attribute.
$user_guid
Validate a user.
Definition: validate.php:6
$owner_guid
$id
River item delete action.
Definition: delete.php:6
$owner
Definition: crop.php:7
initializeAttributes()
Initialize the attributes array.
__construct(stdClass $row=null)
Create an access collection object.
$user
Definition: ban.php:7
$url
Definition: default.php:33
getMembers(array $options=[])
Returns members of the access collection.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
__get($name)
Get an attribute.
getOwnerEntity()
Returns owner entity of the collection.
$value
Definition: debugging.php:7
$site name
hasMember($member_guid=0)
Checks if user is already in access collection.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
$filter
Layout body.
Definition: body.php:18
addMember($member_guid=0)
Adds a new member to access collection.
$comment owner_guid
Definition: save.php:45