diff options
author | Christian Klinger | 2016-06-15 14:37:11 +0200 |
---|---|---|
committer | Christian Klinger | 2016-06-15 14:37:11 +0200 |
commit | 8ee4f89825de178b301fa909532c7111e1dbb3ec (patch) | |
tree | 2205b177e6a045f7fa957afc4e913507faed33b7 /modules-available/exams | |
parent | First version of a visualization. (diff) | |
download | slx-admin-8ee4f89825de178b301fa909532c7111e1dbb3ec.tar.gz slx-admin-8ee4f89825de178b301fa909532c7111e1dbb3ec.tar.xz slx-admin-8ee4f89825de178b301fa909532c7111e1dbb3ec.zip |
Multiple locations per exam.
Diffstat (limited to 'modules-available/exams')
-rw-r--r-- | modules-available/exams/config.json | 2 | ||||
-rw-r--r-- | modules-available/exams/page.inc.php | 45 | ||||
-rw-r--r-- | modules-available/exams/templates/page-add-exam.html | 14 | ||||
-rw-r--r-- | modules-available/exams/templates/page-exams.html | 20 |
4 files changed, 35 insertions, 46 deletions
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 @@ <form class="form" method="POST" action="?do=exams&action=add"> <div class="form-group"> - <label for="location">Location</label> - <select name="location" class="form-control"> + <label for="locations">Location</label> + <select id="locations" multiple="multiple" name="locations[]" class=""> {{#locations}} <option value="{{locationid}}"> {{locationname}} </option> {{/locations}} @@ -13,22 +13,22 @@ <div class="row"> <div class="form-group col-xs-6"> <label for="starttime_date">Start Date</label> - <input class="form-control datepicker" name="starttime_date" /> + <input required class="form-control datepicker" name="starttime_date" /> </div> <div class="form-group col-xs-6"> <label for="starttime_time">Start Time</label> - <input type="text" class="form-control timepicker" name="starttime_time" /> + <input required type="text" class="form-control timepicker" name="starttime_time" /> </div> </div> <div class="row"> <div class="form-group col-xs-6"> <label for="endtime_date">End Date</label> - <input class="form-control datepicker" name="endtime_date" /> + <input required class="form-control datepicker" name="endtime_date" /> </div> <div class="form-group col-xs-6"> <label for="endtime_time">End Time</label> - <input type="texxt" class="form-control timepicker" name="endtime_time" /> + <input required type="texxt" class="form-control timepicker" name="endtime_time" /> </div> </div> <div class="row"> @@ -55,5 +55,7 @@ document.addEventListener("DOMContentLoaded", function () { }; $('.datepicker').datepicker(dateSettings); $('.timepicker').timepicker(timeSettings); + + $('#locations').multiselect({numberDisplayed: 1}); }, false); // --></script> 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}} <tr> <td>{{examid}}</td> - <td> - <a href="?do=baseconfig&module=locations&locationid={{locationid}}"> {{locationname}} </a> - </td> + <td> {{locationnames}} </td> <td>{{starttime}}</td> <td>{{endtime}}</td> <td> @@ -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}}}', |