summaryrefslogtreecommitdiffstats
path: root/modules-available/exams/inc/exams.inc.php
blob: 2a54c2628f1a574d5d68a66c22429c0e893edbca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

class Exams
{

	/**
	 * @param int[] $locationIds of location ids. must be an associative array.
	 * @return bool true iff for any of the given location ids an exam is scheduled.
	 **/
	public static function isInExamMode(array $locationIds, ?string &$lectureId = null, ?string &$autoLogin = null): bool
	{
		if (empty($locationIds)) {
			$locationIds[] = 0;
		}
		$res = Database::queryFirst("SELECT lectureid, autologin FROM exams"
			. " INNER JOIN exams_x_location USING (examid)"
			. " WHERE UNIX_TIMESTAMP() BETWEEN starttime AND endtime AND (locationid IN (:lids) OR locationid IS NULL) LIMIT 1", [
				'lids' => array_values($locationIds),
		]);
		if ($res !== false) {
			$lectureId = $res['lectureid'];
			$autoLogin = $res['autologin'];
		}
		return $res !== false;
	}

}