summaryrefslogtreecommitdiffstats
path: root/modules-available/exams/inc/exams.inc.php
blob: da4dec8588e6e24c683a6854f329eac8ba7d7849 (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
28
29
30
<?php

class Exams
{

	/**
	 * @param int[] of location ids. must bot be an associative array.
	 * @return: bool true iff for any of the given location ids an exam is scheduled.
	 **/
	public static function isInExamMode($locationIds, &$lectureId = false, &$autoLogin = false)
	{
		if (!is_array($locationIds)) {
			$locationIds = array($locationIds);
		}
		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;
	}

}