You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB
PHTML

<?php
use Engelsystem\Database\DB;
8 years ago
function guest_stats()
{
$apiKey = config('api_key');
$request = request();
8 years ago
if ($request->has('api_key')) {
if (!empty($apiKey) && $request->input('api_key') == $apiKey) {
8 years ago
$stats = [];
8 years ago
list($user_count) = DB::select('SELECT count(*) AS `user_count` FROM `User`');
8 years ago
$stats['user_count'] = $user_count['user_count'];
8 years ago
list($arrived_user_count) = DB::select('SELECT count(*) AS `user_count` FROM `User` WHERE `Gekommen`=1');
8 years ago
$stats['arrived_user_count'] = $arrived_user_count['user_count'];
8 years ago
$done_shifts_seconds = DB::selectOne('
SELECT SUM(`Shifts`.`end` - `Shifts`.`start`)
FROM `ShiftEntry`
JOIN `Shifts` USING (`SID`)
WHERE `Shifts`.`end` < UNIX_TIMESTAMP()
');
$done_shifts_seconds = (int)array_shift($done_shifts_seconds);
8 years ago
$stats['done_work_hours'] = round($done_shifts_seconds / (60 * 60), 0);
8 years ago
$users_in_action = DB::select('
SELECT `Shifts`.`start`, `Shifts`.`end`
FROM `ShiftEntry`
JOIN `Shifts` ON `Shifts`.`SID`=`ShiftEntry`.`SID`
WHERE UNIX_TIMESTAMP() BETWEEN `Shifts`.`start` AND `Shifts`.`end`
');
8 years ago
$stats['users_in_action'] = count($users_in_action);
8 years ago
header('Content-Type: application/json');
8 years ago
raw_output(json_encode($stats));
return;
}
raw_output(json_encode([
'error' => 'Wrong api_key.'
8 years ago
]));
}
raw_output(json_encode([
'error' => 'Missing parameter api_key.'
8 years ago
]));
}