summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo
diff options
context:
space:
mode:
authorSimon Rettberg2017-12-05 13:44:20 +0100
committerSimon Rettberg2017-12-05 13:44:20 +0100
commit75e738b2351f91e36451261207abca53f0851ff0 (patch)
tree84a5f7af20e0084864596f0018e383819d6c4867 /modules-available/locationinfo
parent[inc/Util] prettyTime: return '???' if given timestamp is 0 or not a number (diff)
downloadslx-admin-75e738b2351f91e36451261207abca53f0851ff0.tar.gz
slx-admin-75e738b2351f91e36451261207abca53f0851ff0.tar.xz
slx-admin-75e738b2351f91e36451261207abca53f0851ff0.zip
[locationinfo] Fix formatting of calendar starttime/endtime, remove if not possible
The weekcalendar plugin chokes on badly formatted timestamps, so either fix or remove dates which don't match the expectation. Fixes #3192
Diffstat (limited to 'modules-available/locationinfo')
-rw-r--r--modules-available/locationinfo/inc/coursebackend.inc.php34
-rw-r--r--modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php15
2 files changed, 43 insertions, 6 deletions
diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php
index 1fe87202..bf3e2e1f 100644
--- a/modules-available/locationinfo/inc/coursebackend.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend.inc.php
@@ -131,6 +131,19 @@ abstract class CourseBackend
*/
protected abstract function fetchSchedulesInternal($roomId);
+ private static function fixTime(&$start, &$end)
+ {
+ if (!preg_match('/^\d+-\d+-\d+T\d+:\d+:\d+$/', $start) || !preg_match('/^\d+-\d+-\d+T\d+:\d+:\d+$/', $start))
+ return false;
+ $start = strtotime($start);
+ $end = strtotime($end);
+ if ($start >= $end)
+ return false;
+ $start = date('Y-m-d\TH:i:s', $start);
+ $end = date('Y-m-d\TH:i:s', $end);
+ return true;
+ }
+
/**
* Method for fetching the schedule of the given rooms on a server.
*
@@ -184,18 +197,31 @@ abstract class CourseBackend
return false;
}
- if ($this->getCacheTime() > 0) {
- // Caching requested by backend, write to DB
- foreach ($backendResponse as $serverRoomId => $calendar) {
+ foreach ($backendResponse as $serverRoomId => &$calendar) {
+ $calendar = array_values($calendar);
+ for ($i = 0; $i < count($calendar); ++$i) {
+ if (empty($calendar[$i]['title'])) {
+ $calendar[$i]['title'] = '-';
+ }
+ if (!self::fixTime($calendar[$i]['start'], $calendar[$i]['end'])) {
+ error_log("Ignoring calendar entry '{$calendar[$i]['title']}' with bad time format");
+ unset($calendar[$i]);
+ }
+ }
+ $calendar = array_values($calendar);
+ if ($this->getCacheTime() > 0) {
+ // Caching requested by backend, write to DB
$value = json_encode($calendar);
Database::simpleQuery("UPDATE locationinfo_locationconfig SET calendar = :ttable, lastcalendarupdate = :now
- WHERE serverid = :serverid AND serverlocationid = :serverlocationid", array(
+ WHERE serverid = :serverid AND serverlocationid = :serverlocationid", array(
'serverid' => $this->serverId,
'serverlocationid' => $serverRoomId,
'ttable' => $value,
'now' => $NOW
));
}
+
+ unset($calendar);
}
// Add rooms that were requested to the final return value
foreach ($remoteIds as $location => $serverRoomId) {
diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
index e2577284..24e01070 100644
--- a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
@@ -87,13 +87,24 @@ class CourseBackend_Dummy extends CourseBackend
*
* @param $roomIds array with local ID as key and serverId as value
* @return array a recursive array that uses the roomID as key
- * and has the schedule array as value. A shedule array contains an array in this format:
- * ["start"=>'JJJJ-MM-DD HH:MM:SS',"end"=>'JJJJ-MM-DD HH:MM:SS',"title"=>string]
+ * and has the schedule array as value. A schedule array contains an array in this format:
+ * ["start"=>'YYYY-MM-DD<T>HH:MM:SS',"end"=>'YYYY-MM-DD<T>HH:MM:SS',"title"=>string]
*/
public function fetchSchedulesInternal($roomId)
{
$a = array();
foreach ($roomId as $id) {
+ if ($id == 1) {
+ $now = time();
+ return array($id => array(
+ array(
+ 'title' => 'Lange',
+ 'start' => date('Y-m-d', $now) . 'T0:00:00',
+ 'end' => date('Y-m-d', $now + 86400 * 3) . 'T0:00:00',
+ )
+ ));
+ }
+ // Normal
$x = array();
$time = strtotime('today');
$end = strtotime('+7 days', $time);