From 1964cadd8c0c2b6e494b572d3ee05d5118481f62 Mon Sep 17 00:00:00 2001 From: Karsten Tlotzek Date: Mon, 23 Jun 2025 11:10:46 +0200 Subject: [PATCH] =?UTF-8?q?Standardmethoden=20f=C3=BCr=20Standort=20und=20?= =?UTF-8?q?News.Events=20erweitert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/EventController.php | 15 +++++++++ Controller/NewsController.php | 43 ++++++++++++++++++++++++ Controller/StandortController.php | 24 ++++++++++++++ Model/EventModel.php | 17 ++++++++-- Model/NewsModel.php | 53 ++++++++++++++++++++++++++++++ Model/StandortModel.php | 22 +++++++++++++ Views/Event/showEvents.phtml | 32 ++++++++++++++++++ Views/News/showNews.phtml | 28 ++++++++++++++++ Views/Standort/showStandorte.phtml | 36 ++++++++++++++++++++ Views/Ticket/hasTicket.phtml | 11 +++++++ 10 files changed, 278 insertions(+), 3 deletions(-) create mode 100644 Controller/NewsController.php create mode 100644 Controller/StandortController.php create mode 100644 Model/NewsModel.php create mode 100644 Model/StandortModel.php create mode 100644 Views/Event/showEvents.phtml create mode 100644 Views/News/showNews.phtml create mode 100644 Views/Standort/showStandorte.phtml create mode 100644 Views/Ticket/hasTicket.phtml diff --git a/Controller/EventController.php b/Controller/EventController.php index 6c22d15..90fd27f 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -14,6 +14,21 @@ class EventController { $this->view = $view; } + public function showEvents() { + $events = $this->eventModel->getEvents(); + $this->view->setVars([ + "events" => $events + ]); + } + + public function getEvent() { + $ausstellungid = $_GET['ausstellungid']; + $event = $this->eventModel->getEvent($ausstellungid); + $this->view->setVars([ + "event" => $event + ]); + } + public function updateEvent() { $event = array( "ausstellungid" => $_POST['ausstellungid'], diff --git a/Controller/NewsController.php b/Controller/NewsController.php new file mode 100644 index 0000000..a7999a3 --- /dev/null +++ b/Controller/NewsController.php @@ -0,0 +1,43 @@ +newsModel = new NewsModel(); + $this->view = $view; + } + + public function showNews() { + $news = $this->newsModel->getNews(); + $this->view->setVars([ + "news" => $news + ]); + } + + public function createNews() { + $news = [ + "name" => $_POST['name'], + "beschreibung" => $_POST['beschreibung'], + "datum" => $_POST['datum'] + ]; + $this->newsModel->createNews($news); + $this->view->setVars([ + "name" => $_POST['name'] + ]); + } + + public function deleteNews() { + $newsId = $_POST['newsid']; + $this->newsModel->deleteNews($newsId); + $this->view->setVars([ + "deleted" => $newsId + ]); + } +} \ No newline at end of file diff --git a/Controller/StandortController.php b/Controller/StandortController.php new file mode 100644 index 0000000..13b6f6e --- /dev/null +++ b/Controller/StandortController.php @@ -0,0 +1,24 @@ +standortModel = new StandortModel(); + $this->view = $view; + } + + public function showStandorte() { + $this -> standortModel -> getStandorte(); + $this->view->setVars([ + "standorte" => $this->standortModel->getStandorte() + ]); + } + +} \ No newline at end of file diff --git a/Model/EventModel.php b/Model/EventModel.php index e02fd0e..1693528 100644 --- a/Model/EventModel.php +++ b/Model/EventModel.php @@ -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; diff --git a/Model/NewsModel.php b/Model/NewsModel.php new file mode 100644 index 0000000..da61f97 --- /dev/null +++ b/Model/NewsModel.php @@ -0,0 +1,53 @@ +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; + } + } +} \ No newline at end of file diff --git a/Model/StandortModel.php b/Model/StandortModel.php new file mode 100644 index 0000000..c4f08d9 --- /dev/null +++ b/Model/StandortModel.php @@ -0,0 +1,22 @@ +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; + } + } +} \ No newline at end of file diff --git a/Views/Event/showEvents.phtml b/Views/Event/showEvents.phtml new file mode 100644 index 0000000..55ab417 --- /dev/null +++ b/Views/Event/showEvents.phtml @@ -0,0 +1,32 @@ + + +

Alle Ausstellungen

+ + + + + + + + + + + + + + + + + + + + + + + +
NameBeschreibungVonBisMax. Tickets
+ +

Derzeit sind keine Ausstellungen verfügbar.

+ + + \ No newline at end of file diff --git a/Views/News/showNews.phtml b/Views/News/showNews.phtml new file mode 100644 index 0000000..5f71b89 --- /dev/null +++ b/Views/News/showNews.phtml @@ -0,0 +1,28 @@ + + +

Alle News

+ + + + + + + + + + + + + + + + + + + +
NameBeschreibungDatum
+ +

Derzeit sind keine News verfügbar.

+ + + \ No newline at end of file diff --git a/Views/Standort/showStandorte.phtml b/Views/Standort/showStandorte.phtml new file mode 100644 index 0000000..3ac6cdb --- /dev/null +++ b/Views/Standort/showStandorte.phtml @@ -0,0 +1,36 @@ + + +

Unsere Standorte

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
StraßeHausnr.PLZOrtLandTelefonEmail
+ +

Keine Standorte gefunden.

+ + + \ No newline at end of file diff --git a/Views/Ticket/hasTicket.phtml b/Views/Ticket/hasTicket.phtml new file mode 100644 index 0000000..c076676 --- /dev/null +++ b/Views/Ticket/hasTicket.phtml @@ -0,0 +1,11 @@ + + +
+

TEST

+
+ + + + \ No newline at end of file