diff options
author | Jannik Schönartz | 2016-12-09 13:13:00 +0100 |
---|---|---|
committer | Jannik Schönartz | 2016-12-09 13:13:00 +0100 |
commit | c4bc0fdd0d9ea72feb2ca2c74a19d9d37588813b (patch) | |
tree | e29e0dc8c38eea66b91d1ab17d3ef09ba3273e70 | |
parent | frontend: einmode svg & config updaterate fix (diff) | |
download | slx-admin-c4bc0fdd0d9ea72feb2ca2c74a19d9d37588813b.tar.gz slx-admin-c4bc0fdd0d9ea72feb2ca2c74a19d9d37588813b.tar.xz slx-admin-c4bc0fdd0d9ea72feb2ca2c74a19d9d37588813b.zip |
LocationInfo: Calendar informations get updated every 15 mins if there is a request. Added the settinglocationinfo column servername
-rw-r--r-- | modules-available/locationinfo/api.inc.php | 36 | ||||
-rw-r--r-- | modules-available/locationinfo/install.inc.php | 19 |
2 files changed, 52 insertions, 3 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index c0b5c2fc..d156f7ab 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -44,7 +44,7 @@ function randomCalendarGenerator() { $result[] = $c; } - echo json_encode($result); + return json_encode($result); } function getRandomWord($len = 10) { @@ -55,7 +55,39 @@ function getRandomWord($len = 10) { function getCalendar($getRoomID) { // TODO GET AND RETURN THE ACTUAL calendar - randomCalendarGenerator(); + //echo randomCalendarGenerator(); + + $dbquery = Database::simpleQuery("SELECT calendar, lastcalendarupdate, serverid, serverroomid FROM `location_info` WHERE locationid=:locationID", array('locationID' => $getRoomID)); + + $calendar; + $lastupdate; + $serverid; + $serverroomid; + while($dbresult=$dbquery->fetch(PDO::FETCH_ASSOC)) { + $lastupdate = (int) $dbresult['lastcalendarupdate']; + $calendar = $dbresult['calendar']; + $serverid = $dbresult['serverid']; + $serverroomid = $dbresult['serverroomid']; + } + + $NOW = time(); + if ($lastupdate == 0 || $NOW - $lastupdate > 900) { + echo updateCalendar($getRoomID, $serverid, $serverroomid); + } else { + echo $calendar; + } +} + +function updateCalendar($locationid, $serverid, $serverroomid) { + // TODO CALL UpdateCalendar($serverid, $serverroomid); + $result = randomCalendarGenerator(); + // ^ replace with the actual call + + // Save in db and update timestamp + $NOW = time(); + Database::exec("UPDATE `location_info` Set calendar=:calendar, lastcalendarupdate=:now WHERE locationid=:id", array('id' => $locationid, 'calendar' => $result, 'now' => $NOW)); + + return $result; } function getConfig($locationID) { diff --git a/modules-available/locationinfo/install.inc.php b/modules-available/locationinfo/install.inc.php index 162f000c..e84bca6f 100644 --- a/modules-available/locationinfo/install.inc.php +++ b/modules-available/locationinfo/install.inc.php @@ -9,7 +9,8 @@ $res[] = tableCreate('location_info', ' `hidden` BOOLEAN NOT NULL DEFAULT 0, `openingtime` VARCHAR(2000) NOT NULL, `config` VARCHAR(2000) NOT NULL, - `calendar` VARCHAR(2000) NOT NULL, + `calendar` VARCHAR(2000) NOT NULL, + `lastcalendarupdate` INT(11) NOT NULL, PRIMARY KEY (`locationid`) '); @@ -65,6 +66,22 @@ if (!tableHasColumn('location_info', 'serverroomid')) { $res[] = UPDATE_DONE; } +if (!tableHasColumn('location_info', 'lastcalendarupdate')) { + $ret = Database::exec("ALTER TABLE `location_info` ADD `lastcalendarupdate` INT(11) NOT NULL AFTER `calendar`"); + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Adding lastcalendarupdate to location_info failed: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} + +if (!tableHasColumn('setting_location_info', 'servername')) { + $ret = Database::exec("ALTER TABLE `setting_location_info` ADD `servername` INT(11) NOT NULL AFTER `serverid`"); + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Adding servername to setting_location_info failed: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} + if (in_array(UPDATE_DONE, $res)) { finalResponse(UPDATE_DONE, 'Tables created successfully'); } |