summaryrefslogtreecommitdiffstats
path: root/modules-available/exams
diff options
context:
space:
mode:
authorSimon Rettberg2016-06-23 17:05:06 +0200
committerSimon Rettberg2016-06-23 17:05:06 +0200
commit46b3d8983aecd4908bb0b00ca9f1ccf73c4d5ff8 (patch)
tree855302e92464eb0295290d332f1adb7b35fb5a3c /modules-available/exams
parent[exams] Fix vis.js when an exam is active in more than one location (id colli... (diff)
downloadslx-admin-46b3d8983aecd4908bb0b00ca9f1ccf73c4d5ff8.tar.gz
slx-admin-46b3d8983aecd4908bb0b00ca9f1ccf73c4d5ff8.tar.xz
slx-admin-46b3d8983aecd4908bb0b00ca9f1ccf73c4d5ff8.zip
[exams] Add baseconfig API hook
Diffstat (limited to 'modules-available/exams')
-rw-r--r--modules-available/exams/baseconfig/getconfig.inc.php8
-rw-r--r--modules-available/exams/inc/exams.inc.php31
2 files changed, 27 insertions, 12 deletions
diff --git a/modules-available/exams/baseconfig/getconfig.inc.php b/modules-available/exams/baseconfig/getconfig.inc.php
new file mode 100644
index 00000000..d26a20a9
--- /dev/null
+++ b/modules-available/exams/baseconfig/getconfig.inc.php
@@ -0,0 +1,8 @@
+<?php
+
+if (isset($configVars["SLX_LOCATIONS"])) {
+ $locationIds = explode(' ', $configVars["SLX_LOCATIONS"]);
+ if (Exams::isInExamMode($locationIds)) {
+ $configVars['SLX_EXAM'] = 'yes';
+ }
+}
diff --git a/modules-available/exams/inc/exams.inc.php b/modules-available/exams/inc/exams.inc.php
index 9e5833ba..c01d4bad 100644
--- a/modules-available/exams/inc/exams.inc.php
+++ b/modules-available/exams/inc/exams.inc.php
@@ -1,17 +1,24 @@
<?php
-class Exams {
+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)
+ {
+ if (!is_array($locationIds)) {
+ $locationIds = array($locationIds);
+ } elseif (empty($locationIds)) {
+ return false;
+ }
+ $l = str_repeat(',?', count($locationIds) - 1);
+ $res = Database::queryFirst("SELECT examid FROM exams"
+ . " INNER JOIN exams_x_location USING (examid)"
+ . " WHERE UNIX_TIMESTAMP() BETWEEN starttime AND endtime AND locationid IN (?$l) LIMIT 1", $locationIds);
+ return $res !== false;
+ }
- /**
- * @param: array of location ids
- * @return: true iff for any of the given location ids an exam is scheduled
- **/
- public static function isInExamMode($locationIds) {
- // TODO: Better use prepared statement
- $l = '(' . implode(', ', $locationIds) . ')';
- $res = Database::queryFirst("SELECT (COUNT(examid) > 0) as examMode FROM exams WHERE starttime < NOW() AND endtime > NOW() AND locationid IN $l", []);
-
- return $res['examMode'];
- }
}