summaryrefslogtreecommitdiffstats
path: root/modules-available/exams/inc/exams.inc.php
blob: e95a9392728191f5e9f58f5b71042ef2325271f3 (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[] 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)
	{
		if (!is_array($locationIds)) {
			$locationIds = array($locationIds);
		} elseif (empty($locationIds)) {
			return false;
		}
		$l = str_repeat(',?', count($locationIds));
		$res = Database::queryFirst("SELECT lectureid 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'];
		}
		return $res !== false;
	}

}