diff options
author | Christian Klinger | 2016-06-15 13:04:15 +0200 |
---|---|---|
committer | Christian Klinger | 2016-06-15 13:04:15 +0200 |
commit | a0139c37aaafa845157335627ece7a5a88f4085f (patch) | |
tree | ed4319e1651533e1dcb2bb014e77caceb5aae762 /modules-available/exams/page.inc.php | |
parent | Added date and time pickers. (diff) | |
download | slx-admin-a0139c37aaafa845157335627ece7a5a88f4085f.tar.gz slx-admin-a0139c37aaafa845157335627ece7a5a88f4085f.tar.xz slx-admin-a0139c37aaafa845157335627ece7a5a88f4085f.zip |
First version of a visualization.
Diffstat (limited to 'modules-available/exams/page.inc.php')
-rw-r--r-- | modules-available/exams/page.inc.php | 115 |
1 files changed, 103 insertions, 12 deletions
diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php index 78d5b21c..c0b6c48d 100644 --- a/modules-available/exams/page.inc.php +++ b/modules-available/exams/page.inc.php @@ -5,6 +5,95 @@ class Page_Exams extends Page var $action; var $exams; var $locations; + var $lectures; + + + protected function readLocations() + { + $tmp = Database::simpleQuery("select * from location;", []); + while ($loc = $tmp->fetch(PDO::FETCH_ASSOC)) { + $this->locations[] = $loc; + } + } + + protected function readExams() + { + $tmp = Database::simpleQuery("select * from exams NATURAL LEFT OUTER JOIN location;", []); + while ($exam = $tmp->fetch(PDO::FETCH_ASSOC)) { + $this->exams[] = $exam; + } + + } + + protected function readLectures() + { + $tmp = Database::simpleQuery("select * from sat.lecture NATURAL JOIN sat.lecture_x_location"); + while ($lecture = $tmp->fetch(PDO::FETCH_ASSOC)) { + $this->lectures[] = $lecture; + } + } + + protected function makeItemsForVis() + { + $out = []; + /* foreach group also add an invisible item on top */ + foreach ($this->locations as $l) { + $out[] = [ 'id' => 'spacer_' . $l['locationid'], + 'group' => $l['locationid'], + 'className' => 'spacer', + 'start' => 0, + 'content' => 'spacer', + 'end' => 99999999999999, + 'subgroup' => 0 + ]; + + } + 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 */ + } + /* add the lectures */ + $i = 2; + foreach ($this->lectures as $l) { + $out[] = [ + 'id' => $l['lectureid'], + 'content' => $l['displayname'], + 'start' => date(DATE_ISO8601, $l['starttime']), + 'end' => date(DATE_ISO8601, $l['endtime']), + 'group' => $l['locationid'], + 'subgroup' => $i++ + ]; + + } + + return json_encode($out); + } + + protected function makeGroupsForVis() + { + $out = []; + foreach ($this->locations as $l) { + $out[] = [ + 'id' => $l['locationid'], + 'content' => $l['locationname'] + ]; + } + return json_encode($out); + } protected function doPreprocess() { @@ -16,24 +105,20 @@ class Page_Exams extends Page } if ($this->action === 'show') { - $tmp = Database::simpleQuery("select * from exams NATURAL LEFT OUTER JOIN location;", []); - while ($exam = $tmp->fetch(PDO::FETCH_ASSOC)) { - $this->exams[] = $exam; - } + $this->readExams(); + $this->readLocations(); + $this->readLectures(); } elseif ($this->action === 'add') { - $tmp = Database::simpleQuery("select * from location;", []); - while ($loc = $tmp->fetch(PDO::FETCH_ASSOC)) { - $this->locations[] = $loc; - } - + $this->readLocations(); if (Request::isPost()) { /* process form-data */ $locationid = Request::post('location'); $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) VALUES(:locationid, :starttime, :endtime);", - compact('locationid', 'starttime', 'endtime')); + $res = Database::exec("INSERT INTO exams(locationid, starttime, endtime, description) VALUES(:locationid, :starttime, :endtime, :description);", + compact('locationid', 'starttime', 'endtime', 'description')); if ($res === false) { Message::addError('exam-not-added'); @@ -65,7 +150,13 @@ class Page_Exams extends Page if ($this->action === "show") { Render::setTitle("All Exams"); - Render::addTemplate('page-exams', ['exams' => $this->exams]); + Render::addTemplate('page-exams', + [ 'exams' => $this->exams, + 'exams_json' => $this->makeItemsForVis(), + 'rooms_json' => $this->makeGroupsForVis(), + 'vis_begin' => date('Y-m-d'), + 'vis_end' => date('Y-m-d', strtotime("+2 day")) + ]); } elseif ($this->action === "add") { Render::setTitle("Add Exam"); Render::addTemplate('page-add-exam', ['locations' => $this->locations]); |