diff options
author | msquare <msquare@notrademark.de> | 2017-12-11 22:26:36 +0100 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2017-12-11 22:26:36 +0100 |
commit | 74f3677f19b70bbe6655f2d9d9a42792b22120de (patch) | |
tree | 7ec4fc344348f528934442a05cff63386afb1da7 /includes/controller/public_dashboard_controller.php | |
parent | afb77d22ba35dfbee74bbbee95626d55edef8898 (diff) |
add quick+dirty public dashboard
Diffstat (limited to 'includes/controller/public_dashboard_controller.php')
-rw-r--r-- | includes/controller/public_dashboard_controller.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/includes/controller/public_dashboard_controller.php b/includes/controller/public_dashboard_controller.php new file mode 100644 index 00000000..dc81ba2c --- /dev/null +++ b/includes/controller/public_dashboard_controller.php @@ -0,0 +1,70 @@ +<?php +use Engelsystem\Database\Db; + +/** + * Loads all data for the public dashboard + */ +function public_dashboard_controller() +{ + $stats = []; + + $now = time(); + $in3hours = $now + 3 * 60 * 60; + $result = Db::selectOne(" + SELECT SUM( + (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`) + - (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) + ) as `count` + FROM `Shifts` + WHERE ((`end` > ? AND `end` < ?) OR (`start` > ? AND `start` < ?))", [ + $now, + $in3hours, + $now, + $in3hours + ]); + $stats['needed-3-hours'] = $result['count']; + + $night_start = parse_date('Y-m-d H:i', date('Y-m-d', time() + 12 * 60 * 60) . ' 02:00'); + $night_end = $night_start + 6 * 60 * 60; + $result = Db::selectOne(" + SELECT SUM( + (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`) + - (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) + ) as `count` + FROM `Shifts` + WHERE ((`end` > ? AND `end` < ?) OR (`start` > ? AND `start` < ?))", [ + $night_start, + $night_end, + $night_start, + $night_end + ]); + $stats['needed-night'] = $result['count']; + + $result = Db::selectOne(" + SELECT SUM( + (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) + ) as `count` + FROM `Shifts` + WHERE (`end` >= ? AND `start` <= ?)", [ + time(), + time() + ]); + $stats['angels-working'] = $result['count']; + + $result = Db::selectOne(" + SELECT ROUND(SUM( + (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) + * (`Shifts`.`end` - `Shifts`.`start`)/3600 + )) as `count` + FROM `Shifts` + WHERE `end` >= ?", [ + time() + ]); + $stats['hours-to-work'] = $result['count']; + + return [ + 'Engelsystem Public Dashboard', + public_dashboard_view($stats) + ]; +} +?>
\ No newline at end of file |