Controller und Tickets vereinheitlicht (CRUD)

This commit is contained in:
2025-06-23 14:46:12 +02:00
parent 66ff531ba4
commit d8865cbd27
16 changed files with 559 additions and 213 deletions

View File

@@ -8,14 +8,95 @@ class StandortModel extends Database {
public function getStandorte() {
$pdo = $this->linkDB();
$sql = "SELECT * from standort ORDER BY ort;";
$sql = "SELECT * FROM Standort ORDER BY standortid ASC;";
try {
$sth = $pdo->prepare($sql);
$sth->execute();
return $sth->fetchAll(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Lesen der Daten.", $e);
new \Blog\Library\ErrorMsg("Fehler beim Lesen der Standorte.", $e);
die;
}
}
public function getStandort($standortid) {
$pdo = $this->linkDB();
$sql = "SELECT * FROM Standort WHERE standortid = :standortid;";
$params = [":standortid" => $standortid];
try {
$sth = $pdo->prepare($sql);
$sth->execute($params);
return $sth->fetch(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Lesen des Standorts.", $e);
die;
}
}
public function createStandort($data) {
$pdo = $this->linkDB();
$sql = "INSERT INTO Standort (straße, hausnr, postleitzahl, ort, land, tel, email)
VALUES (:straße, :hausnr, :postleitzahl, :ort, :land, :tel, :email);";
$params = [
":straße" => $data['straße'],
":hausnr" => $data['hausnr'],
":postleitzahl" => $data['postleitzahl'],
":ort" => $data['ort'],
":land" => $data['land'],
":tel" => $data['tel'],
":email" => $data['email']
];
try {
$sth = $pdo->prepare($sql);
$sth->execute($params);
return $pdo->lastInsertId();
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Anlegen des Standorts.", $e);
die;
}
}
public function updateStandort($standortid, $data) {
$pdo = $this->linkDB();
$sql = "UPDATE Standort SET
straße = :straße,
hausnr = :hausnr,
postleitzahl = :postleitzahl,
ort = :ort,
land = :land,
tel = :tel,
email = :email
WHERE standortid = :standortid;";
$params = [
":straße" => $data['straße'],
":hausnr" => $data['hausnr'],
":postleitzahl" => $data['postleitzahl'],
":ort" => $data['ort'],
":land" => $data['land'],
":tel" => $data['tel'],
":email" => $data['email'],
":standortid" => $standortid
];
try {
$sth = $pdo->prepare($sql);
$sth->execute($params);
return $sth->rowCount();
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Aktualisieren des Standorts.", $e);
die;
}
}
public function deleteStandort($standortid) {
$pdo = $this->linkDB();
$sql = "DELETE FROM Standort WHERE standortid = :standortid;";
$params = [":standortid" => $standortid];
try {
$sth = $pdo->prepare($sql);
$sth->execute($params);
return $sth->rowCount();
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Löschen des Standorts.", $e);
die;
}
}