Elgg  Version 6.1
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 }
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_default_access(\ElggUser $user=null, array $input_params=[])
Gets the default access permission.
Definition: access.php:56
$user_guid
Definition: login_as.php:10
foreach($keys as $key=> $default_value) $entity
Definition: access.php:44
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$input_params
Definition: livesearch.php:15
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_get_ignore_access()
Functions for Elgg&#39;s access system for entities, metadata, and annotations.
Definition: access.php:16
$entity_guid
Action for adding and editing comments.
Definition: save.php:6
$params
Definition: access.php:29
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:121
$owner_guid
elgg_get_access_collections(array $options=[])
Returns access collections.
Definition: access.php:175
elgg_has_access_to_entity(int $entity_guid, int $user_guid=0)
Can a user access an entity.
Definition: access.php:91
$user
Definition: ban.php:7
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_access_array(int $user_guid=0)
Returns an array of access IDs a user is permitted to see.
Definition: access.php:39
$subtype
Definition: delete.php:22
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
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_collection(int $collection_id)
Get a specified access collection.
Definition: access.php:164