Elgg  Version master
access.php
Go to the documentation of this file.
1 <?php
16 function elgg_get_ignore_access(): bool {
17  return _elgg_services()->session_manager->getIgnoreAccess();
18 }
19 
39 function elgg_get_access_array(int $user_guid = 0): array {
40  return _elgg_services()->accessCollections->getAccessArray($user_guid);
41 }
42 
56 function elgg_get_default_access(?\ElggUser $user = null, array $input_params = []): int {
57  // site default access
58  $default_access = (int) _elgg_services()->config->default_access;
59 
60  // default to logged in user
61  $user = $user ?? _elgg_services()->session_manager->getLoggedInUser();
62 
63  // user default access if enabled
64  if (_elgg_services()->config->allow_user_default_access && $user instanceof \ElggUser) {
65  $user_access = $user->elgg_default_access;
66  if ($user_access !== null) {
67  $default_access = (int) $user_access;
68  }
69  }
70 
71  $params = [
72  'user' => $user,
73  'default_access' => $default_access,
74  'input_params' => $input_params,
75  ];
76  return (int) _elgg_services()->events->triggerResults('default', 'access', $params, $default_access);
77 }
78 
91 function elgg_has_access_to_entity(int $entity_guid, int $user_guid = 0): bool {
92  $entity = elgg_call(ELGG_IGNORE_ACCESS, function() use ($entity_guid) {
93  return _elgg_services()->entityTable->get($entity_guid);
94  });
95 
96  if (!$entity instanceof \ElggEntity) {
97  return false;
98  }
99 
100  return _elgg_services()->accessCollections->hasAccessToEntity($entity, $user_guid);
101 }
102 
129 function elgg_get_write_access_array(int $user_guid = 0, bool $flush = false, array $input_params = []): array {
130  return _elgg_services()->accessCollections->getWriteAccessArray($user_guid, $flush, $input_params);
131 }
132 
147 function elgg_create_access_collection(string $name, int $owner_guid = 0, ?string $subtype = null): ?\ElggAccessCollection {
148  $acl = new \ElggAccessCollection();
149  $acl->name = $name;
150  $acl->owner_guid = $owner_guid ?: _elgg_services()->session_manager->getLoggedInUserGuid();
151  $acl->subtype = $subtype;
152 
153  return $acl->save() ? $acl : null;
154 }
155 
164 function elgg_get_access_collection(int $collection_id): ?\ElggAccessCollection {
165  return _elgg_services()->accessCollections->get($collection_id);
166 }
167 
175 function elgg_get_access_collections(array $options = []): array {
176  return _elgg_services()->accessCollections->getEntityCollections($options);
177 }
178 
196 function elgg_get_readable_access_level(int $entity_access_id): string {
197  return _elgg_services()->accessCollections->getReadableAccessLevel($entity_access_id);
198 }
if(! $user||! $user->canDelete()) $name
Definition: delete.php:22
$entity_guid
Action for adding and editing comments.
Definition: save.php:6
$subtype
Definition: delete.php:22
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
$owner_guid
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:121
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags.
Definition: elgglib.php:306
elgg_get_ignore_access()
Functions for Elgg's access system for entities, metadata, and annotations.
Definition: access.php:16
elgg_has_access_to_entity(int $entity_guid, int $user_guid=0)
Can a user access an entity.
Definition: access.php:91
elgg_get_access_collections(array $options=[])
Returns access collections.
Definition: access.php:175
elgg_get_access_collection(int $collection_id)
Get a specified access collection.
Definition: access.php:164
elgg_get_default_access(?\ElggUser $user=null, array $input_params=[])
Gets the default access permission.
Definition: access.php:56
elgg_get_readable_access_level(int $entity_access_id)
Return the name of an ACCESS_* constant or an access collection, but only if the logged in user has w...
Definition: access.php:196
elgg_get_write_access_array(int $user_guid=0, bool $flush=false, array $input_params=[])
Returns an array of access permissions that the user is allowed to save content with.
Definition: access.php:129
elgg_create_access_collection(string $name, int $owner_guid=0, ?string $subtype=null)
Creates a new access collection.
Definition: access.php:147
elgg_get_access_array(int $user_guid=0)
Returns an array of access IDs a user is permitted to see.
Definition: access.php:39
$input_params
Definition: livesearch.php:15
$user_guid
Definition: login_as.php:10
foreach($keys as $key=> $default_value) $entity
Definition: access.php:44
$params
Definition: access.php:29