Bristol SU Support Package
helpers.php
Go to the documentation of this file.
1 <?php
2 
9 
10 if (!function_exists('settings')) {
19  function settings($key = null, $default = null)
20  {
21  if ($key === null) {
22  $settings = [];
23  app()->make(ModuleInstance::class)->moduleInstanceSettings->each(function($setting) use (&$settings) {
24  $settings[$setting->key] = $setting->value;
25  });
26  return $settings;
27  } else {
28  try {
29  return app()->make(ModuleInstance::class)->moduleInstanceSettings()->where('key', $key)->firstOrFail()->value;
30  } catch (ModelNotFoundException $e) {
31  return $default;
32  }
33  }
34  }
35 }
36 
37 if (!function_exists('alias')) {
44  function alias() {
45  $moduleInstance = app()->make(ModuleInstance::class);
46  if ($moduleInstance->exists) {
47  return $moduleInstance->alias;
48  }
49  throw new Exception('Alias cannot be returned outside a module environment');
50  }
51 }
52 
53 if (!function_exists('hasPermission')) {
66  function hasPermission(string $ability, ?User $userModel = null, ?Group $group = null, ?Role $role = null): bool {
67  if ($userModel === null && $group === null && $role === null) {
68  return \BristolSU\Support\Permissions\Facade\PermissionTester::evaluate($ability);
69  }
70  return \BristolSU\Support\Permissions\Facade\PermissionTester::evaluateFor($ability, $userModel, $group, $role);
71  }
72 
73 }