Files
thetool/application/Api/v1/Modules/Operationaldata/Snopp.php
2025-02-12 15:31:12 +01:00

96 lines
2.8 KiB
PHP

<?php
namespace application\Api\v1\Modules\Operationaldata;
use application\Api\v1\Modules;
require_once(APPDIR."/Api/v1/Modules/ApiControllerModule.php");
/*
* API Endpoints for Operationaldata from SNOPP
*/
class Snopp extends Modules\ApiControllerModule
{
public function init()
{
}
public function setPreorderConnected($req_id) {
if(!$req_id) {
return \mfResponse::BadRequest(["message" => "id missing"]);
}
$wohneinheit = false;
if(is_numeric($req_id)) {
$id = $req_id;
$wohneinheit = new \ADBWohneinheit($id);
}
if(!$wohneinheit || !$wohneinheit->id) {
$oaid = $req_id;
$wohneinheit = \ADBWohneinheitModel::getFirst(["oaid" => $oaid]);
if (!$wohneinheit) {
return \mfResponse::NotFound(["message" => "Home not found"]);
}
}
//print_r($wohneinheit);
$preorder = \PreorderModel::getFirstActive(["adb_wohneinheit_id" => $wohneinheit->id]);
if(!$preorder) {
return \mfResponse::NotFound(["message" => "Home not found"]);
}
$new_status = \PreorderstatusModel::getFirst(["code" => 300]);
if(!$new_status) {
return \mfResponse::InternalServerError();
}
if($preorder->status->code < $new_status->code) {
$preorder->status_id = $new_status->id;
$preorder->edit_by = $this->me->id;
$preorder->save();
}
//print_r($preorder);exit;
return \mfResponse::Ok(["message" => "OK"]);
}
public function setPreorderActive($req_id) {
if(!$req_id) {
return \mfResponse::BadRequest(["message" => "id missing"]);
}
$wohneinheit = false;
if(is_numeric($req_id)) {
$id = $req_id;
$wohneinheit = new \ADBWohneinheit($id);
}
if(!$wohneinheit || !$wohneinheit->id) {
$oaid = $req_id;
$wohneinheit = \ADBWohneinheitModel::getFirst(["oaid" => $oaid]);
if (!$wohneinheit) {
return \mfResponse::NotFound(["message" => "Home not found"]);
}
}
$preorder = \PreorderModel::getFirstActive(["adb_wohneinheit_id" => $wohneinheit->id]);
if(!$preorder) {
return \mfResponse::NotFound(["message" => "Home not found"]);
}
$new_status = \PreorderstatusModel::getFirst(["code" => 500]);
if(!$new_status) {
return \mfResponse::InternalServerError();
}
if($preorder->status->code < $new_status->code) {
$preorder->status_id = $new_status->id;
$preorder->edit_by = $this->me->id;
$preorder->save();
}
return \mfResponse::Ok(["message" => "OK"]);
}
}