From 8ee4f89825de178b301fa909532c7111e1dbb3ec Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Wed, 15 Jun 2016 14:37:11 +0200 Subject: Multiple locations per exam. --- modules-available/exams/config.json | 2 +- modules-available/exams/page.inc.php | 45 ++++++++++++---------- .../exams/templates/page-add-exam.html | 14 ++++--- modules-available/exams/templates/page-exams.html | 20 +--------- 4 files changed, 35 insertions(+), 46 deletions(-) (limited to 'modules-available/exams') diff --git a/modules-available/exams/config.json b/modules-available/exams/config.json index 6590a595..b39f0365 100644 --- a/modules-available/exams/config.json +++ b/modules-available/exams/config.json @@ -1,5 +1,5 @@ { "category":"main.status", - "dependencies": [ "locations", "visjs", "bootstrap_datepicker", "bootstrap_timepicker"], + "dependencies": [ "locations", "visjs", "bootstrap_datepicker", "bootstrap_timepicker", "bootstrap_multiselect"], "permission": "0" } 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 { diff --git a/modules-available/exams/templates/page-add-exam.html b/modules-available/exams/templates/page-add-exam.html index a537e7e9..ebbccd6b 100644 --- a/modules-available/exams/templates/page-add-exam.html +++ b/modules-available/exams/templates/page-add-exam.html @@ -2,8 +2,8 @@
- - {{#locations}} {{/locations}} @@ -13,22 +13,22 @@
- +
- +
- +
- +
@@ -55,5 +55,7 @@ document.addEventListener("DOMContentLoaded", function () { }; $('.datepicker').datepicker(dateSettings); $('.timepicker').timepicker(timeSettings); + + $('#locations').multiselect({numberDisplayed: 1}); }, false); // --> diff --git a/modules-available/exams/templates/page-exams.html b/modules-available/exams/templates/page-exams.html index 8758b408..95c73d34 100644 --- a/modules-available/exams/templates/page-exams.html +++ b/modules-available/exams/templates/page-exams.html @@ -12,9 +12,7 @@ {{#exams}} {{examid}} - - {{locationname}} - + {{locationnames}} {{starttime}} {{endtime}} @@ -38,11 +36,7 @@ function customOrder(a, b) { - console.log("a is "); - console.log(a); - console.log("b is "); - console.log(b); - return 1000; + return 1000; // just in order of appeareance } document.addEventListener("DOMContentLoaded", function () { @@ -53,16 +47,6 @@ document.addEventListener("DOMContentLoaded", function () { console.log(items_plain); var groups = new vis.DataSet(groups_plain); var items = new vis.DataSet(items_plain); - // var groups = new vis.DataSet([ - // { id: 1, content:'RZ -101' }, - // { id: 2, content:'RZ -104' } - // ]); - // var items = new vis.DataSet([ - // { id: 1, group: 1, content: 'Bio 1', start: '2016-06-15 10:30', end : '2016-06-15 14:45'}, - // { id: 2, group: 1, content: 'Bio 2', start: '2016-06-15 10:45', end : '2016-06-15 15:00'}, - // { id: 3, group: 2, content: 'Englisch', start: '2016-06-15 16:00', end : '2016-06-15 17:15'}, - // { id: 4, group: 1, content: 'BACKGROUND', start: '2016-06-15-11:00', end: '2016-06-15 18:00', type: 'background'} - // ]); var options = { 'start' : '{{{vis_begin}}}', -- cgit v1.2.3-55-g7522