Adb wohneinheit/add contacts

This commit is contained in:
Luca Haid
2025-09-16 14:10:03 +00:00
parent fd39ba1db2
commit 0496103841
6 changed files with 371 additions and 2 deletions
@@ -237,4 +237,50 @@ class ADBWohneinheitController extends mfBaseController {
"IS_ADMIN" => $isAdmin,
]);
}
protected function getContactsAction() {
$post = json_decode(file_get_contents('php://input'), true);
if (empty($post['id'])) {
self::returnJson(['success' => false, 'message' => 'Wohneinheit ID fehlt.']);
return;
}
$unit = new ADBWohneinheit($post['id']);
if (!$unit->id) {
self::returnJson(['success' => false, 'message' => 'Wohneinheit nicht gefunden.']);
return;
}
$contact = $unit->contact;
$contacts = !empty($contact) ? json_decode($contact, true) : [];
self::returnJson(['success' => true, 'contacts' => $contacts, 'header' =>
($unit->hausnummer->strasse ? $unit->hausnummer->strasse->name : '') . ' ' .
($unit->hausnummer ? $unit->hausnummer->hausnummer : '') . ', ' .
($unit->hausnummer->plz ? $unit->hausnummer->plz->plz : '') . ' ' .
($unit->hausnummer->ortschaft ? $unit->hausnummer->ortschaft->name : '')
]);
}
protected function saveContactsAction() {
$post = json_decode(file_get_contents('php://input'), true);
if (empty($post['id']) || !isset($post['data'])) {
self::returnJson(['success' => false, 'message' => 'ID oder Daten fehlen.']);
return;
}
$unit = new ADBWohneinheit($post['id']);
if (!$unit->id) {
self::returnJson(['success' => false, 'message' => 'Wohneinheit nicht gefunden.']);
return;
}
$unit->contact = json_encode($post['data']);
if ($unit->save()) {
self::returnJson(['success' => true, 'message' => 'Kontakt erfolgreich gespeichert.']);
} else {
self::returnJson(['success' => false, 'message' => 'Fehler beim Speichern der Kontakt.']);
}
}
}