Elgg  Version 4.3
ElggAccessCollection.php
Go to the documentation of this file.
1 <?php
2 
4 
13 
19  public function __construct(stdClass $row = null) {
20  $this->initializeAttributes();
21 
22  foreach ((array) $row as $key => $value) {
23  $this->attributes[$key] = $value;
24  }
25  }
26 
33  protected function initializeAttributes() {
34  parent::initializeAttributes();
35 
36  $this->attributes['id'] = null;
37  $this->attributes['owner_guid'] = null;
38  $this->attributes['name'] = null;
39  $this->attributes['subtype'] = null;
40  }
41 
51  public function __set($name, $value) {
52  if (in_array($name, ['id', 'owner_guid', 'subtype'])) {
53  throw new ElggRuntimeException("$name can not be set at runtime");
54  }
55  $this->attributes[$name] = $value;
56  }
57 
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 
76  public function getOwnerEntity() {
77  return _elgg_services()->entityTable->get($this->owner_guid);
78  }
79 
84  public function getDisplayName() {
85 
86  $filter = function($name = null) {
87  if (!isset($name)) {
88  $name = _elgg_services()->translator->translate('access:limited:label');
89  }
90  $params = [
91  'access_collection' => $this,
92  ];
93  return (string) _elgg_services()->hooks->trigger('access_collection:name', $this->getType(), $params, $name);
94  };
95 
96  $user = _elgg_services()->session->getLoggedInUser();
97  $owner = $this->getOwnerEntity();
98  if (!$user || !$owner) {
99  // User is not logged in or does not access to the owner entity:
100  // return default 'Limited' label
101  return $filter();
102  }
103 
104  if ($user->isAdmin() || $owner->guid == $user->guid) {
105  return $filter($this->name);
106  }
107 
108  return $filter();
109  }
110 
114  public function save() : bool {
115  if ($this->id > 0) {
116  return _elgg_services()->accessCollections->rename($this->id, $this->name);
117  } else {
118  return (bool) _elgg_services()->accessCollections->create($this->name, $this->owner_guid);
119  }
120  }
121 
125  public function delete() {
126  return _elgg_services()->accessCollections->delete($this->id);
127  }
128 
136  public function canEdit($user_guid = null) {
137  return _elgg_services()->accessCollections->canEdit($this->id, (int) $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 }
$user_guid
Definition: login_as.php:10
removeMember($member_guid=0)
Removes a user from access collection.
$params
Saves global plugin settings.
Definition: save.php:13
$owner
Definition: upload.php:7
elgg_normalize_url($url)
Definition: output.php:153
canEdit($user_guid=null)
Check if user can edit this collection.
$site name
Definition: settings.php:21
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
toObject(array $params=[])
{}
$type
Definition: delete.php:21
$options
Elgg admin footer.
Definition: footer.php:6
getDisplayName()
Get readable access level name for this collection.
$value
Definition: generic.php:51
__set($name, $value)
Set an attribute.
$owner_guid
initializeAttributes()
Initialize the attributes array.
__construct(stdClass $row=null)
Create an access collection object.
$user
Definition: ban.php:7
A generic class that contains shared code among , , and .
Definition: ElggData.php:10
getMembers(array $options=[])
Returns members of the access collection.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
__get($name)
Get an attribute.
getOwnerEntity()
Returns owner entity of the collection.
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
$subtype
Definition: delete.php:22
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition: deactivate.php:39
hasMember($member_guid=0)
Checks if user is already in access collection.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
$filter
Layout body.
Definition: body.php:18
addMember($member_guid=0)
Adds a user to access collection.
$id
Generic annotation delete action.
Definition: delete.php:6