From 3f4b8b80c34dbe9177b3e95befbd2bbb90933d4d Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 14 Nov 2024 19:57:33 +0100 Subject: [PATCH] Added Maintenanceinfo Api Controller --- .../Api/v1/MaintenanceinfoApicontroller.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 application/Api/v1/MaintenanceinfoApicontroller.php 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