103 lines
3.3 KiB
PHP
103 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace Blog\Model;
|
|
|
|
use PDOException;
|
|
|
|
class StandortModel extends Database {
|
|
|
|
public function getStandorte() {
|
|
$pdo = $this->linkDB();
|
|
$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 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 (strasse, hausnr, plz, ort, land, tel, email)
|
|
VALUES (:strasse, :hausnr, :plz, :ort, :land, :tel, :email);";
|
|
$params = [
|
|
":strasse" => $data['strasse'],
|
|
":hausnr" => $data['hausnr'],
|
|
":plz" => $data['plz'],
|
|
":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
|
|
strasse = :strasse,
|
|
hausnr = :hausnr,
|
|
plz = :plz,
|
|
ort = :ort,
|
|
land = :land,
|
|
tel = :tel,
|
|
email = :email
|
|
WHERE standortid = :standortid;";
|
|
$params = [
|
|
":strasse" => $data['strasse'],
|
|
":hausnr" => $data['hausnr'],
|
|
":plz" => $data['plz'],
|
|
":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;
|
|
}
|
|
}
|
|
} |