forked from gizmore/phpgdo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule_Perf.php
More file actions
64 lines (57 loc) · 1.32 KB
/
Module_Perf.php
File metadata and controls
64 lines (57 loc) · 1.32 KB
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
<?php
namespace GDO\Perf;
use GDO\Core\GDO_Module;
use GDO\Core\GDT_Enum;
use GDO\User\GDO_User;
use GDO\UI\GDT_Page;
/**
* 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.
*
* @author gizmore
* @version 7.0.0
* @since 5.3.0
* @see GDT_PerfBar
*/
final class Module_Perf extends GDO_Module
{
public int $priority = 100;
public function onLoadLanguage() : void
{
$this->loadLanguage('lang/perf');
}
##############
### Config ###
##############
public function getConfig() : array
{
return [
GDT_Enum::make('hook_sidebar')->enumValues('all', 'none', 'staff')->initial('staff'),
];
}
public function cfgBottomPermission() : string { return $this->getConfigValue('hook_sidebar'); }
############
### Hook ###
############
/**
* Show performance footer.
*/
public function onInitSidebar() : void
{
if ($this->shouldShow())
{
GDT_Page::instance()->bottomBar()->addField(GDT_PerfBar::make('perf'));
}
}
private function shouldShow() : bool
{
switch ($this->cfgBottomPermission())
{
case 'all': return true;
case 'none': return false;
case 'staff': return GDO_User::current()->hasPermission('staff');
}
}
}