This repository has been archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.php
114 lines (98 loc) · 3.63 KB
/
dashboard.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
use SVBX\Report;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
require 'vendor/autoload.php';
require 'WeeklyDelta.php';
require 'session.php';
// init context with some defaults
$context = [
'session' => $_SESSION,
'title' => 'Home',
'pageHeading' => 'Database Information',
'data' => [
'selected' => [
'field' => 'severity',
'from' => null,
'to' => null,
'milestone' => null
]
]
];
if (!empty($_GET)) {
$context['data']['selected']['field'] = filter_var($_GET['field'], FILTER_SANITIZE_STRING);
$context['data']['selected']['from'] = filter_var($_GET['from'], FILTER_SANITIZE_STRING);
$context['data']['selected']['to'] = filter_var($_GET['to'], FILTER_SANITIZE_STRING);
$context['data']['selected']['milestone'] = filter_var($_GET['milestone'], FILTER_SANITIZE_STRING);
}
// defaults
$context['data']['selected']['to'] = new CarbonImmutable($context['data']['selected']['to']);
$context['data']['selected']['from'] = ($context['data']['selected']['from']
? new CarbonImmutable($context['data']['selected']['from'])
: $context['data']['selected']['to']->subWeek())->toDateString();
$context['data']['selected']['to'] = $context['data']['selected']['to']->toDateString();
$context['data']['selected']['milestone'] = intval($context['data']['selected']['milestone'])
?: null;
$link = new MysqliDb(DB_CREDENTIALS);
$context['data']['status'] = $link->
orderBy('statusID', 'ASC')->
groupBy('statusName')->
where('CDL.status', '3', '<>')->
join('CDL', 'status.statusID = CDL.status', 'LEFT')->
get('status', null, ['statusName label', 'COUNT(CDL.status) count']);
$context['data']['severity'] = $link->
orderBy('severityName', 'ASC')->
groupBy('severityName')->
join('CDL', 'severity.severityID = CDL.severity', 'LEFT')->
get('severity', null, ['severityName label', 'COUNT(IF(status = 1, 1, NULL)) count']);
$context['data']['system'] = $link->
orderBy('systemName', 'ASC')->
groupBy('systemName')->
// where('CDL.status', '3', '<>')->
join('CDL', 'system.systemID = CDL.groupToResolve', 'LEFT')->
join('users_enc', 'system.lead = users_enc.userid', 'LEFT')->
get('system', null, ['systemName', 'COUNT(IF(status = 1, 1, NULL)) as count']);
$context['data']['location'] = $link->
orderBy('locationName', 'ASC')->
groupBy('locationName')->
// where('CDL.status', '3', '<>')->
join('CDL', 'location.locationID = CDL.location', 'LEFT')->
get('location', null, ['locationName', 'COUNT(IF(status = 1, 1, NULL)) as count']);
$statusOrder = [
'Open',
'VTA_PPR_PNDG',
'VTA_CLOSED',
'Closed'
];
usort($context['data']['status'], function($a, $b) use ($statusOrder) {
return array_search($a['label'], $statusOrder) - array_search($b['label'], $statusOrder);
});
// instantiate Twig
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, [
'debug' => getenv('PHP_ENV') === 'dev'
]);
if (getenv('PHP_ENV') === 'dev') $twig->addExtension(new Twig_Extension_Debug());
$context['data']['milestones'] = array_reduce(
$link->get('requiredBy', null, [ 'reqByID as id', 'requiredBy as name' ]),
function ($map, $row) {
$map[$row['id']] = $row['name'];
return $map;
},
[]
);
$link->disconnect();
// instantiate report object
try {
$report = Report::delta(
$context['data']['selected']['field'],
$context['data']['selected']['from'],
$context['data']['selected']['to'],
$context['data']['selected']['milestone']
);
$context['data']['deltaReport'] = $report->get();
} catch (Exception | Error $e) {
error_log($e);
$context['data']['deltaReport']['error'] = $e->getMessage();
}
$twig->display('dashboard.html.twig', $context);