Elgg  Version 6.2
EntityCapabilitiesService.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
12 
18  protected $entities = [];
19 
30  public function hasCapability(string $type, string $subtype, string $capability, bool $default = false): bool {
31  return elgg_extract($capability, elgg_extract($subtype, elgg_extract($type, $this->entities, []), [])) ?? $default;
32  }
33 
44  public function setCapability(string $type, string $subtype, string $capability, bool $value): void {
45  if (!isset($this->entities[$type])) {
46  $this->entities[$type] = [];
47  }
48 
49  if (!isset($this->entities[$type][$subtype])) {
50  $this->entities[$type][$subtype] = [];
51  }
52 
53  $this->entities[$type][$subtype][$capability] = $value;
54  }
55 
63  public function getTypesWithCapability(string $capability): array {
64  $result = [];
65 
66  foreach ($this->entities as $type => $subtypes) {
67  foreach ($subtypes as $subtype => $capabilities) {
68  if (elgg_extract($capability, $capabilities) !== true) {
69  continue;
70  }
71 
72  if (!isset($result[$type])) {
73  $result[$type] = [];
74  }
75 
76  $result[$type][] = $subtype;
77  }
78  }
79 
80  return $result;
81  }
82 }
$subtype
Definition: delete.php:22
$type
Definition: delete.php:21
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
hasCapability(string $type, string $subtype, string $capability, bool $default=false)
Checks if a capability is enabled for a specified type/subtype.
setCapability(string $type, string $subtype, string $capability, bool $value)
Sets the capability value for a specified type/subtype.
getTypesWithCapability(string $capability)
Returns an array of type/subtypes with the requested capability enabled.
$subtypes
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:256
$value
Definition: generic.php:51
$default
Definition: checkbox.php:30
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