summaryrefslogtreecommitdiffstats
path: root/modules-available/exams/page.inc.php
diff options
context:
space:
mode:
authorChristian Klinger2016-06-15 14:37:11 +0200
committerChristian Klinger2016-06-15 14:37:11 +0200
commit8ee4f89825de178b301fa909532c7111e1dbb3ec (patch)
tree2205b177e6a045f7fa957afc4e913507faed33b7 /modules-available/exams/page.inc.php
parentFirst version of a visualization. (diff)
downloadslx-admin-8ee4f89825de178b301fa909532c7111e1dbb3ec.tar.gz
slx-admin-8ee4f89825de178b301fa909532c7111e1dbb3ec.tar.xz
slx-admin-8ee4f89825de178b301fa909532c7111e1dbb3ec.zip
Multiple locations per exam.
Diffstat (limited to 'modules-available/exams/page.inc.php')
-rw-r--r--modules-available/exams/page.inc.php45
1 files changed, 24 insertions, 21 deletions
diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php
index c0b6c48d..8c82f50e 100644
--- a/modules-available/exams/page.inc.php
+++ b/modules-available/exams/page.inc.php
@@ -18,11 +18,12 @@ class Page_Exams extends Page
protected function readExams()
{
- $tmp = Database::simpleQuery("select * from exams NATURAL LEFT OUTER JOIN location;", []);
+ $tmp = Database::simpleQuery("select examid, starttime, endtime, GROUP_CONCAT(locationid) AS locationids,"
+ . " GROUP_CONCAT(locationname) AS locationnames from "
+ . "exams NATURAL JOIN exams_x_locations NATURAL JOIN location GROUP BY examid;", []);
while ($exam = $tmp->fetch(PDO::FETCH_ASSOC)) {
$this->exams[] = $exam;
}
-
}
protected function readLectures()
@@ -48,23 +49,17 @@ class Page_Exams extends Page
];
}
+ $unique_ids = 1;
foreach ($this->exams as $e) {
- // $out[] = [ 'id' => $e['examid'],
- // 'content' => $e['description'],
- // 'start' => $e['starttime'],
- // 'end' => $e['endtime'],
- // 'group' => $e['locationid'],
- // 'subgroup' => $i++
- // ];
- /* show them only as a red shadow */
- $out[] = [ 'id' => 'shadow_' . $e['examid'],
- 'content' => '',
- 'start' => $e['starttime'],
- 'end' => $e['endtime'],
- 'type' => 'background',
- 'group' => $e['locationid'],
- ];
- /* also add the shadow for all subrooms */
+ foreach(explode(',', $e['locationids']) as $locationid) {
+ $out[] = [ 'id' => 'shadow_' . $unique_ids++,
+ 'content' => '',
+ 'start' => $e['starttime'],
+ 'end' => $e['endtime'],
+ 'type' => 'background',
+ 'group' => $locationid,
+ ];
+ }
}
/* add the lectures */
$i = 2;
@@ -112,13 +107,20 @@ class Page_Exams extends Page
$this->readLocations();
if (Request::isPost()) {
/* process form-data */
- $locationid = Request::post('location');
+ $locationids = Request::post('locations', [], "ARRAY");
+
$starttime = Request::post('starttime_date') . " " . Request::post('starttime_time');
$endtime = Request::post('endtime_date') . " " . Request::post('endtime_time');
$description = Request::post('description');
- $res = Database::exec("INSERT INTO exams(locationid, starttime, endtime, description) VALUES(:locationid, :starttime, :endtime, :description);",
- compact('locationid', 'starttime', 'endtime', 'description'));
+ $res = Database::exec("INSERT INTO exams(starttime, endtime, description) VALUES(:starttime, :endtime, :description);",
+ compact('starttime', 'endtime', 'description'));
+
+ $exam_id = Database::lastInsertId();
+ foreach ($locationids as $lid) {
+ $res = $res && Database::exec("INSERT INTO exams_x_locations(examid, locationid) VALUES(:exam_id, :lid)", compact('exam_id', 'lid'));
+ }
+
if ($res === false) {
Message::addError('exam-not-added');
@@ -132,6 +134,7 @@ class Page_Exams extends Page
if (!Request::isPost()) { die('delete only works with a post request'); }
$examid = Request::post('examid');
$res = Database::exec("DELETE FROM exams WHERE examid = :examid;", compact('examid'));
+ $res = Database::exec("DELETE FROM exams_x_locations WHERE examid = :examid;", compact('examid'));
if ($res === false) {
Message::addError('exam-not-deleted-error');
} else {