Elgg  Version 6.2
ElggAccessCollection.php
Go to the documentation of this file.
1 <?php
2 
12 
18  public function __construct(?\stdClass $row = null) {
19  $this->initializeAttributes();
20 
21  foreach ((array) $row as $key => $value) {
22  $this->attributes[$key] = $value;
23  }
24  }
25 
32  protected function initializeAttributes(): void {
33  parent::initializeAttributes();
34 
35  $this->attributes['id'] = null;
36  $this->attributes['owner_guid'] = _elgg_services()->session_manager->getLoggedInUserGuid();
37  $this->attributes['name'] = null;
38  $this->attributes['subtype'] = null;
39  }
40 
50  public function __set($name, $value): void {
51  switch ($name) {
52  case 'id':
53  $value = (int) $value;
54  break;
55  case 'subtype':
56  if (isset($value)) {
57  $value = trim((string) $value);
58  if (strlen($value) > 255) {
59  throw new \Elgg\Exceptions\LengthException('The "subtype" of an ElggAccessCollection cannot be greated than 255 characters');
60  }
61  }
62  break;
63  case 'name':
64  $value = trim((string) $value);
65  if (empty($value)) {
66  throw new \Elgg\Exceptions\LengthException('The "name" of an ElggAccessCollection cannot be empty');
67  }
68  break;
69  case 'owner_guid':
70  $value = (int) $value;
71  if (!_elgg_services()->entityTable->exists($value)) {
72  throw new \Elgg\Exceptions\InvalidArgumentException("The 'owner_guid' ({$value}) for the ElggAccessColelction doesn't seem to exists");
73  }
74  break;
75  }
76 
77  $this->attributes[$name] = $value;
78  }
79 
87  public function __get($name) {
88  return $this->attributes[$name] ?? null;
89  }
90 
96  public function getOwnerEntity(): ?\ElggEntity {
97  return _elgg_services()->entityTable->get($this->owner_guid);
98  }
99 
105  public function getDisplayName(): string {
106 
107  $filter = function($name = null) {
108  if (!isset($name)) {
109  $name = _elgg_services()->translator->translate('access:limited:label');
110  }
111 
112  $params = [
113  'access_collection' => $this,
114  ];
115  return (string) _elgg_services()->events->triggerResults('access_collection:name', $this->getType(), $params, $name);
116  };
117 
118  $user = _elgg_services()->session_manager->getLoggedInUser();
119  $owner = $this->getOwnerEntity();
120  if (!$user || !$owner) {
121  // User is not logged in or does not access to the owner entity:
122  // return default 'Limited' label
123  return $filter();
124  }
125 
126  if ($user->isAdmin() || $owner->guid == $user->guid) {
127  return $filter($this->name);
128  }
129 
130  return $filter();
131  }
132 
136  public function save(): bool {
137  if ($this->id > 0) {
138  return _elgg_services()->accessCollections->update($this);
139  }
140 
141  return _elgg_services()->accessCollections->create($this);
142  }
143 
147  public function delete(): bool {
148  return _elgg_services()->accessCollections->delete($this);
149  }
150 
158  public function canEdit(?int $user_guid = null): bool {
159  return _elgg_services()->accessCollections->canEdit($this->id, $user_guid);
160  }
161 
169  public function getMembers(array $options = []) {
170  return _elgg_services()->accessCollections->getMembers($this->id, $options);
171  }
172 
180  public function hasMember(int $member_guid = 0): bool {
181  return _elgg_services()->accessCollections->hasUser($member_guid, $this->id);
182  }
183 
191  public function addMember(int $member_guid = 0): bool {
192  return _elgg_services()->accessCollections->addUser($member_guid, $this->id);
193  }
194 
202  public function removeMember(int $member_guid = 0): bool {
203  return _elgg_services()->accessCollections->removeUser($member_guid, $this->id);
204  }
205 
209  public function getURL(): string {
210  $type = $this->getType();
211  $params = [
212  'access_collection' => $this,
213  ];
214  $url = _elgg_services()->events->triggerResults('access_collection:url', $type, $params);
215  return elgg_normalize_url($url);
216  }
217 
221  public function toObject(array $params = []) {
222  $object = new \Elgg\Export\AccessCollection();
223  $object->type = $this->getType();
224  $object->subtype = $this->getSubtype();
225  $object->id = $this->id;
226  $object->owner_guid = $this->owner_guid;
227  $object->name = $this->name;
228 
229  $params['access_collection'] = $this;
230 
231  return _elgg_services()->events->triggerResults('to:object', 'access_collection', $params, $object);
232  }
233 
237  public function getSystemLogID(): int {
238  return (int) $this->id;
239  }
240 
244  public function getObjectFromID(int $id) {
245  return _elgg_services()->accessCollections->get($id);
246  }
247 
251  public function getType(): string {
252  return 'access_collection';
253  }
254 
258  public function getSubtype(): string {
259  if (isset($this->subtype)) {
260  return $this->subtype;
261  }
262 
263  return $this->name;
264  }
265 }
$site name
Definition: settings.php:15
if(! $user||! $user->canDelete()) $name
Definition: delete.php:22
$id
Generic annotation delete action.
Definition: delete.php:6
$owner
Definition: upload.php:7
$subtype
Definition: delete.php:22
$type
Definition: delete.php:21
$params
Saves global plugin settings.
Definition: save.php:13
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
$user
Definition: ban.php:7
if(!elgg_is_empty($icon_alt) &&!str_starts_with($icon_alt, '<')) switch( $type)
Definition: button.php:64
getDisplayName()
Get readable access level name for this collection.
__set($name, $value)
Set an attribute.
addMember(int $member_guid=0)
Adds a user to access collection.
initializeAttributes()
Initialize the attributes array.
getType()
{Return the type of the object - eg.object, group, user, relationship, metadata, annotation etcstring...
getURL()
{Get a URL for this object.string}
hasMember(int $member_guid=0)
Checks if user is already in access collection.
__construct(?\stdClass $row=null)
Create an access collection object.
__get($name)
Get an attribute.
getObjectFromID(int $id)
{For a given ID, return the object associated with it.This is used by the river functionality primari...
toObject(array $params=[])
{Get a plain old object copy for public consumption.Export parameters\Elgg\Export\Data}
canEdit(?int $user_guid=null)
Check if user can edit this collection.
getSubtype()
{Return a subtype.For metadata & annotations this is the 'name' and for relationship this is the rela...
removeMember(int $member_guid=0)
Removes a user from access collection.
save()
{Save this data to the appropriate database table.bool}
getMembers(array $options=[])
Returns members of the access collection.
getSystemLogID()
{Return an identification for the object for storage in the system log.This id must be an integer....
getOwnerEntity()
Returns owner entity of the collection.
A generic class that contains shared code among \ElggExtender, \ElggEntity, and \ElggRelationship.
Definition: ElggData.php:12
$owner_guid
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition: deactivate.php:39
if($email instanceof \Elgg\Email) $object
Definition: body.php:24
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
$value
Definition: generic.php:51
$user_guid
Definition: login_as.php:10
elgg_normalize_url(string $url)
Definition: output.php:163
$filter
Layout content filter.
Definition: filter.php:18
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
Definition: robots.php:10