finish basic public dashboard
parent
d5631297dc
commit
ff94df53d6
@ -1,70 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
use Engelsystem\Database\Db;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all data for the public dashboard
|
* Loads all data for the public dashboard
|
||||||
*/
|
*/
|
||||||
function public_dashboard_controller()
|
function public_dashboard_controller()
|
||||||
{
|
{
|
||||||
$stats = [];
|
$stats = [
|
||||||
|
'needed-3-hours' => stats_angels_needed_three_hours(),
|
||||||
$now = time();
|
'needed-night' => stats_angels_needed_for_nightshifts(),
|
||||||
$in3hours = $now + 3 * 60 * 60;
|
'angels-working' => stats_currently_working(),
|
||||||
$result = Db::selectOne("
|
'hours-to-work' => stats_hours_to_work()
|
||||||
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("
|
$free_shifts = Shifts_free(time(), time() + 12 * 60 * 60);
|
||||||
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 [
|
return [
|
||||||
'Engelsystem Public Dashboard',
|
_('Engelsystem Public Dashboard'),
|
||||||
public_dashboard_view($stats)
|
public_dashboard_view($stats, $free_shifts)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
use Engelsystem\Database\Db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of angels currently working.
|
||||||
|
*/
|
||||||
|
function stats_currently_working()
|
||||||
|
{
|
||||||
|
$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()
|
||||||
|
]);
|
||||||
|
if (empty($result['count'])) {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
return $result['count'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of hours still to work.
|
||||||
|
*/
|
||||||
|
function stats_hours_to_work()
|
||||||
|
{
|
||||||
|
$result = Db::selectOne("
|
||||||
|
SELECT ROUND(SUM(
|
||||||
|
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
|
||||||
|
* (`Shifts`.`end` - `Shifts`.`start`)/3600
|
||||||
|
)) as `count`
|
||||||
|
FROM `Shifts`
|
||||||
|
WHERE `end` >= ?", [
|
||||||
|
time()
|
||||||
|
]);
|
||||||
|
if (empty($result['count'])) {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
return $result['count'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of needed angels in the next 3 hours
|
||||||
|
*/
|
||||||
|
function stats_angels_needed_three_hours()
|
||||||
|
{
|
||||||
|
$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
|
||||||
|
]);
|
||||||
|
if (empty($result['count'])) {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
return $result['count'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of needed angels for nightshifts (between 2 and 8)
|
||||||
|
*/
|
||||||
|
function stats_angels_needed_for_nightshifts()
|
||||||
|
{
|
||||||
|
$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
|
||||||
|
]);
|
||||||
|
if (empty($result['count'])) {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
return $result['count'];
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue