array_values($locationIds), ]); if ($res !== false) { $lectureId = $res['lectureid']; $autoLogin = $res['autologin']; } return $res !== false; } /** * Check if the system is plausibly in exam mode and retrieve relevant information. * Returns array of arrays with keys: * - examtitle (string) - Description of the exam * - estart (int) - Start time of the exam as a UNIX timestamp * - eend (int) - End time of the exam as a UNIX timestamp * - lecturetitle (string) - Display name of the lecture * - lstart (int) - Start time of the linked lecture as a UNIX timestamp * - lend (int) - End time of the linked lecture as a UNIX timestamp * - machines (int) - Count of machines * * @return array{examtitle: string, estart: int, eend: int, lecturetitle: string, lstart: int, lend: int, machines: int}[] **/ public static function plausiblyInExamMode(): array { $res = Database::simpleQuery("SELECT e.description AS examtitle, e.starttime AS estart, e.endtime AS eend, l.displayname AS lecturetitle, l.starttime AS lstart, l.endtime AS lend, Count(m.machineuuid) AS machines FROM exams e LEFT JOIN sat.lecture l USING (lectureid) LEFT JOIN exams_x_location exl USING (examid) LEFT JOIN machine m ON (m.locationid = exl.locationid AND m.state <> 'OFFLINE') WHERE UNIX_TIMESTAMP() BETWEEN e.starttime AND e.endtime GROUP BY e.examid"); $return = []; $now = time(); foreach ($res as $row) { $duration = $row['eend'] - $row['estart']; if ($duration > 86400 && $row['lstart'] !== null) { // Too long, consider assigned lecture bounds if ($now > $row['lstart'] && $now < $row['lend']) { $duration = $row['lend'] - $row['lstart']; } } if ($duration > 86400 && (int)$row['machines'] === 0) { continue; // Too long, no machines, ignore } $return[] = $row; } return $return; } }