Standardmethoden für Standort und News.Events erweitert

This commit is contained in:
2025-06-23 11:10:46 +02:00
parent 6e3e3708b2
commit 1964cadd8c
10 changed files with 278 additions and 3 deletions

View File

@@ -6,8 +6,19 @@ use PDOException;
class EventModel extends Database {
public function showEvents() {
public function getEvents() {
$pdo = $this->linkDB();
$sql = "SELECT * from ausstellung ORDER BY datum_von DESC;";
try {
$sth = $pdo->prepare($sql);
$sth->execute();
$erg = $sth->fetchAll(\PDO::FETCH_ASSOC);
return $erg;
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Lesen der Daten.", $e);
die;
}
}
public function updateEvent($event) {
@@ -77,7 +88,7 @@ class EventModel extends Database {
$sth = $pdo->prepare($sql);
$sth->execute($params);
$erg = $sth->fetchAll(\PDO::FETCH_ASSOC);
return $erg[0];
return $erg;
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e);
die;

53
Model/NewsModel.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
namespace Blog\Model;
use PDOException;
class NewsModel extends Database {
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;
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Lesen der News.", $e);
die;
}
}
public function createNews($news) {
$pdo = $this->linkDB();
$sql = "INSERT INTO news (`name`, `beschreibung`, `datum`) VALUES (:titel, :inhalt, :datum);";
$params = [
":name" => $news['name'],
":beschreibung" => $news['beschreibung'],
":datum" => $news['datum']
];
try {
$sth = $pdo->prepare($sql);
$sth->execute($params);
return $sth;
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Schreiben der News.", $e);
die;
}
}
public function deleteNews($newsId) {
$pdo = $this->linkDB();
$sql = "DELETE FROM news WHERE newsid = :newsid;";
$params = [":newsid" => $newsId];
try {
$sth = $pdo->prepare($sql);
$sth->execute($params);
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Löschen der News.", $e);
die;
}
}
}

22
Model/StandortModel.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace Blog\Model;
use PDOException;
class StandortModel extends Database {
public function getStandorte() {
$pdo = $this->linkDB();
$sql = "SELECT * from standort ORDER BY ort;";
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);
die;
}
}
}