AddressDB Status change UI
This commit is contained in:
@@ -742,6 +742,12 @@ class AddressDBController extends mfBaseController {
|
||||
case "findAddress":
|
||||
$return = $this->findAddressApi();
|
||||
break;
|
||||
case "updateAddressStatus":
|
||||
$return = $this->updateAddressStatusApi();
|
||||
break;
|
||||
case "updateUnitStatus":
|
||||
$return = $this->updateUnitStatusApi();
|
||||
break;
|
||||
case "getFilteredBuildings":
|
||||
$return = $this->getFilteredBuildingsApi();
|
||||
break;
|
||||
@@ -783,7 +789,117 @@ class AddressDBController extends mfBaseController {
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
|
||||
private function updateAddressStatusApi() {
|
||||
$address_id = $this->request->id;
|
||||
|
||||
if(!is_numeric($address_id) || $address_id < 1) {
|
||||
return ["error" => 1];
|
||||
return false;
|
||||
}
|
||||
|
||||
$address = new ADBHausnummer($address_id);
|
||||
if(!$address->id) {
|
||||
return ["error" => 2];
|
||||
return false;
|
||||
}
|
||||
|
||||
$status_id = $this->request->status_id;
|
||||
if(!is_numeric($status_id) || $status_id < 1) {
|
||||
return ["error" => 3];
|
||||
return false;
|
||||
}
|
||||
|
||||
$status = new ADBStatus($status_id);
|
||||
if(!$status->id) {
|
||||
return ["error" => 4];
|
||||
return false;
|
||||
}
|
||||
|
||||
$address->status_id = $status_id;
|
||||
$address->save();
|
||||
|
||||
$update = [
|
||||
"id" => $address_id,
|
||||
"status_id" => $status_id,
|
||||
"status_code" => $status->code,
|
||||
"status_text" => $status->name,
|
||||
"units" => []
|
||||
];
|
||||
|
||||
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $address->id]) as $affected_unit) {
|
||||
$up = [
|
||||
"id" => $affected_unit->id,
|
||||
"status_id" => $affected_unit->status_id,
|
||||
"status_code" => $affected_unit->status->code,
|
||||
"status_text" => $affected_unit->status->name,
|
||||
];
|
||||
|
||||
$update["units"][] = $up;
|
||||
}
|
||||
|
||||
return ["message" => "Status saved successfully", "id" => $address_id, "updates" => $update];
|
||||
}
|
||||
|
||||
private function updateUnitStatusApi() {
|
||||
$unit_id = $this->request->id;
|
||||
|
||||
if(!is_numeric($unit_id) || $unit_id < 1) {
|
||||
return ["error" => 1];
|
||||
return false;
|
||||
}
|
||||
|
||||
$unit = new ADBWohneinheit($unit_id);
|
||||
if(!$unit->id) {
|
||||
return ["error" => 2];
|
||||
return false;
|
||||
}
|
||||
|
||||
$status_id = $this->request->status_id;
|
||||
if(!is_numeric($status_id) || $status_id < 1) {
|
||||
return ["error" => 3];
|
||||
return false;
|
||||
}
|
||||
|
||||
$status = new ADBStatus($status_id);
|
||||
if(!$status->id) {
|
||||
return ["error" => 4];
|
||||
return false;
|
||||
}
|
||||
|
||||
$linkes_units = [];
|
||||
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $unit->hausnummer_id]) as $lu) {
|
||||
$linkes_units[$lu->id] = $lu->status_id;
|
||||
}
|
||||
|
||||
$unit->status_id = $status_id;
|
||||
$unit->save();
|
||||
|
||||
$update = [
|
||||
"id" => $unit_id,
|
||||
"status_id" => $status_id,
|
||||
"status_code" => $status->code,
|
||||
"status_text" => $status->name,
|
||||
"units" => []
|
||||
];
|
||||
|
||||
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $unit->hausnummer_id]) as $affected_unit) {
|
||||
if(!array_key_exists($affected_unit->id, $linkes_units)) continue;
|
||||
if($linkes_units[$affected_unit->id] == $affected_unit->status_id) continue;
|
||||
|
||||
$up = [
|
||||
"id" => $affected_unit->id,
|
||||
"status_id" => $affected_unit->status_id,
|
||||
"status_code" => $affected_unit->status->code,
|
||||
"status_text" => $affected_unit->status->name,
|
||||
];
|
||||
|
||||
$update["units"][] = $up;
|
||||
}
|
||||
|
||||
return ["message" => "Status saved successfully", "id" => $unit_id, "updates" => $update];
|
||||
}
|
||||
|
||||
private function getUnitApi() {
|
||||
$id = $this->request->id;
|
||||
if(!$id) return false;
|
||||
|
||||
Reference in New Issue
Block a user