summaryrefslogtreecommitdiffstats
path: root/modules-available/exams/inc/exams.inc.php
blob: dfc3827344049003836c2920c68b5c5e3f75e08b (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
<?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);
		}
		$l = str_repeat(',?', count($locationIds));
		$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 (0$l) LIMIT 1", $locationIds);
		if ($res !== false) {
			$lectureId = $res['lectureid'];
			$autoLogin = $res['autologin'];
		}
		return $res !== false;
	}

}