Added Maintenanceinfo Api Controller

This commit is contained in:
Frank Schubert
2024-11-14 19:57:33 +01:00
parent 86aefc975d
commit 3f4b8b80c3

View File

@@ -0,0 +1,42 @@
<?php
class MaintenanceinfoApicontroller extends mfBaseApicontroller {
public function init() {
$this->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);
}
}