diff --git a/application/Api/v1/MaintenanceinfoApicontroller.php b/application/Api/v1/MaintenanceinfoApicontroller.php new file mode 100644 index 000000000..c583a1029 --- /dev/null +++ b/application/Api/v1/MaintenanceinfoApicontroller.php @@ -0,0 +1,42 @@ +addRoute("/maintenanceinfo/current", "getCurrentMaintenance", "GET"); + } + + protected function authenticated() { + if($this->me->username != "xinon-at-maintenance-api-user") { + return \mfResponse::Forbidden(); + } + } + + protected function getCurrentMaintenance() { + $results = []; + + foreach(\MaintenanceNotification::searchActive([]) as $notification) { + $item = []; + + $from = new DateTime("@".$notification->from); + $from->setTimezone(new DateTimeZone("Europe/Vienna")); + $to = new DateTime("@".$notification->to); + $to->setTimezone(new DateTimeZone("Europe/Vienna")); + + $item["from"] = $from->format("c"); + $item["to"] = $to->format("c"); + $item["from_ts"] = $notification->from; + $item["to_ts"] = $notification->to; + $item["subject"] = $notification->subject->subject; + $item["text"] = $notification->getReplacedBody(); + $item["plz_list"] = $notification->plzs; + + $results[] = $item; + } + + return \mfResponse::Ok($results); + + + } + +} \ No newline at end of file