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

@@ -6,14 +6,46 @@ use PDOException;
class NewsModel extends Database {
public function getNewsById($newsId) {
$pdo = $this->linkDB();
$sql = "SELECT * FROM news WHERE newsid = :newsid;";
$params = [":newsid" => $newsId];
try {
$sth = $pdo->prepare($sql);
$sth->execute($params);
return $sth->fetch(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Lesen der News.", $e);
die;
}
}
public function updateNews($newsId, $news) {
$pdo = $this->linkDB();
$sql = "UPDATE news SET name = :name, beschreibung = :beschreibung, datum = :datum WHERE newsid = :newsid;";
$params = [
":name" => $news['titel'],
":beschreibung" => $news['inhalt'],
":datum" => $news['datum'],
":newsid" => $newsId
];
try {
$sth = $pdo->prepare($sql);
$sth->execute($params);
return $sth;
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Aktualisieren der News.", $e);
die;
}
}
public function getNews() {
$pdo = $this->linkDB();
$sql = "SELECT * FROM news ORDER BY datum DESC;";
try {
$sth = $pdo->prepare($sql);
$sth->execute();
$erg = $sth->fetchAll(\PDO::FETCH_ASSOC);
return $erg;
return $sth->fetchAll(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Lesen der News.", $e);
die;
@@ -22,10 +54,10 @@ class NewsModel extends Database {
public function createNews($news) {
$pdo = $this->linkDB();
$sql = "INSERT INTO news (`name`, `beschreibung`, `datum`) VALUES (:titel, :inhalt, :datum);";
$sql = "INSERT INTO news (name, beschreibung, datum) VALUES (:name, :beschreibung, :datum);";
$params = [
":name" => $news['name'],
":beschreibung" => $news['beschreibung'],
":name" => $news['titel'],
":beschreibung" => $news['inhalt'],
":datum" => $news['datum']
];
try {