-
Notifications
You must be signed in to change notification settings - Fork 1
/
Module_Perf.php
73 lines (63 loc) · 1.31 KB
/
Module_Perf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
namespace GDO\Perf;
use GDO\Core\GDO_Module;
use GDO\Core\GDT_Enum;
use GDO\UI\GDT_Page;
use GDO\User\GDO_User;
/**
* Performance statistics in footer.
*
* Config perf_bottom_bar to restrict footer to staff or all or none.
* This module is part of the gdo7 core.
*
* @version 7.0.3
* @since 5.3.0
* @author gizmore
* @see GDT_PerfBar
*/
final class Module_Perf extends GDO_Module
{
public int $priority = 99;
public function onLoadLanguage(): void
{
$this->loadLanguage('lang/perf');
}
##############
### Config ###
##############
public function getConfig(): array
{
return [
GDT_Enum::make('hook_sidebar')->notNull()->enumValues('all', 'none', 'staff')->initial('staff'),
];
}
/**
* Show performance footer.
*/
public function onInitSidebar(): void
{
if ($this->shouldShow())
{
GDT_Page::instance()->bottomBar()->addField(GDT_PerfBar::make('perf'));
}
}
############
### Hook ###
############
private function shouldShow(): bool
{
switch ($this->cfgBottomPermission())
{
case 'all':
return true;
case 'none':
return false;
case 'staff':
return GDO_User::current()->hasPermission('staff');
default:
return false;
}
}
public function cfgBottomPermission(): string { return $this->getConfigValue('hook_sidebar'); }
}