diff options
Diffstat (limited to 'includes/model/Stats.php')
-rw-r--r-- | includes/model/Stats.php | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/includes/model/Stats.php b/includes/model/Stats.php index 0c581fa9..4ff376c6 100644 --- a/includes/model/Stats.php +++ b/includes/model/Stats.php @@ -1,36 +1,43 @@ <?php + use Engelsystem\Database\Db; /** * Returns the number of angels currently working. + * + * @return int|string */ function stats_currently_working() { $result = Db::selectOne(" SELECT SUM( (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) - ) as `count` + ) 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. + * + * @return int|string */ function stats_hours_to_work() { $result = Db::selectOne(" - SELECT ROUND(SUM(`count`)) as `count` FROM ( + SELECT ROUND(SUM(`count`)) AS `count` FROM ( SELECT (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`) - * (`Shifts`.`end` - `Shifts`.`start`)/3600 as `count` + * (`Shifts`.`end` - `Shifts`.`start`)/3600 AS `count` FROM `Shifts` WHERE `end` >= ? AND `Shifts`.`PSID` IS NULL @@ -39,11 +46,11 @@ function stats_hours_to_work() SELECT (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`) - * (`Shifts`.`end` - `Shifts`.`start`)/3600 as `count` + * (`Shifts`.`end` - `Shifts`.`start`)/3600 AS `count` FROM `Shifts` WHERE `end` >= ? AND NOT `Shifts`.`PSID` IS NULL - ) as `tmp` + ) AS `tmp` ", [ time(), time() @@ -56,17 +63,19 @@ function stats_hours_to_work() /** * Returns the number of needed angels in the next 3 hours + * + * @return int|string */ function stats_angels_needed_three_hours() { $now = time(); $in3hours = $now + 3 * 60 * 60; $result = Db::selectOne(" - SELECT SUM(`count`) as `count` FROM ( + SELECT SUM(`count`) AS `count` FROM ( SELECT (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` + AS `count` FROM `Shifts` WHERE `end` > ? AND `start` < ? AND `Shifts`.`PSID` IS NULL @@ -76,11 +85,11 @@ function stats_angels_needed_three_hours() SELECT (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`) - (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) - as `count` + AS `count` FROM `Shifts` WHERE `end` > ? AND `start` < ? AND NOT `Shifts`.`PSID` IS NULL - ) as `tmp`", [ + ) AS `tmp`", [ $now, $in3hours, $now, @@ -94,17 +103,22 @@ function stats_angels_needed_three_hours() /** * Returns the number of needed angels for nightshifts (between 2 and 8) + * + * @return int|string */ 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_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(`count`) as `count` FROM ( + SELECT SUM(`count`) AS `count` FROM ( SELECT (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` + AS `count` FROM `Shifts` WHERE `end` > ? AND `start` < ? AND `Shifts`.`PSID` IS NULL @@ -114,11 +128,11 @@ function stats_angels_needed_for_nightshifts() SELECT (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`) - (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) - as `count` + AS `count` FROM `Shifts` WHERE `end` > ? AND `start` < ? AND NOT `Shifts`.`PSID` IS NULL - ) as `tmp`", [ + ) AS `tmp`", [ $night_start, $night_end, $night_start, @@ -129,5 +143,3 @@ function stats_angels_needed_for_nightshifts() } return $result['count']; } - -?>
\ No newline at end of file |