Added Maintenanceinfo Api Controller
This commit is contained in:
42
application/Api/v1/MaintenanceinfoApicontroller.php
Normal file
42
application/Api/v1/MaintenanceinfoApicontroller.php
Normal 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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user