From 0686e98384b64f29aac512636a50f95649bee901 Mon Sep 17 00:00:00 2001 From: NOrtmann1 <145041949+NOrtmann1@users.noreply.github.com> Date: Wed, 27 May 2026 16:52:06 +0200 Subject: [PATCH] first test --- content/createArticle.php | 18 ---- php/controller/createArticle-controller.php | 30 +++++-- .../createArticle-controller_legacy.php | 18 ++++ php/model/Article.php | 12 +-- php/model/ArticleManager.php | 86 +++--------------- php/model/ArticleManagerDAO.php | 3 +- php/model/LocalArticleManager.php | 88 +++++++++++++++++++ 7 files changed, 145 insertions(+), 110 deletions(-) create mode 100644 php/controller/createArticle-controller_legacy.php create mode 100644 php/model/LocalArticleManager.php diff --git a/content/createArticle.php b/content/createArticle.php index 5655b8d..637f794 100644 --- a/content/createArticle.php +++ b/content/createArticle.php @@ -2,24 +2,6 @@ Seite: Beitrag erstellen Inhalt: Formular für die Erstellung eines neuen Beitrags --> -getMessage()); - } - - if(isset($_POST['title']) && isset($_POST['content']) && isset($_POST['category'])) { - - }else{ - // TODO: Exception werfen. - echo"Fehler!"; - } -?> -
diff --git a/php/controller/createArticle-controller.php b/php/controller/createArticle-controller.php index b49f751..bdab780 100644 --- a/php/controller/createArticle-controller.php +++ b/php/controller/createArticle-controller.php @@ -1,18 +1,32 @@ getMessage()); } -try { - $author = "max.mustermann@web.de"; // wird später aus session bezogen. - $articleManager->addArticle($_Post['title'], $_POST['post-content'], $author); -} catch (Exception $e) { - echo "Fehler beim Erstellen des Beitrags: " . $e->getMessage(); +if ($_SERVER["REQUEST_METHOD"] === "POST") { + if(!isset($_POST["title"]) ||!isset($_POST["content"]) || !isset($_POST["category"])){ + $_SESSION["message"] = "missing_parameters"; + header("location:" . $abs_path . "/index.php?pfad=createArticle"); + } + + $title = $_POST["title"]; + $content = $_POST["content"]; + $category = $_POST["category"]; + $author = "max.mustermann"; // TODO: später aus Session den angemeldeten Nutzer beziehen. + $tags = $_POST["tags"]; + + $articleManager->addArticle($title, $content, $category, $author, $tags); + + // Weiterleitung zur Homepage + header("location:". $abs_path . "/index.php"); + exit(); } ?> \ No newline at end of file diff --git a/php/controller/createArticle-controller_legacy.php b/php/controller/createArticle-controller_legacy.php new file mode 100644 index 0000000..e84c7ef --- /dev/null +++ b/php/controller/createArticle-controller_legacy.php @@ -0,0 +1,18 @@ +getMessage()); +} + +try { + $author = "max.mustermann@web.de"; // wird später aus session bezogen. + $articleManager->addArticle($_Post['title'], $_POST['post-content'], $author); +} catch (Exception $e) { + echo "Fehler beim Erstellen des Beitrags: " . $e->getMessage(); +} +?> \ No newline at end of file diff --git a/php/model/Article.php b/php/model/Article.php index e2bdec7..8c9cdee 100644 --- a/php/model/Article.php +++ b/php/model/Article.php @@ -11,7 +11,7 @@ class Article private $title; private $content; private $author; - private $date; + private $creationDate; private $category; /** @@ -22,16 +22,16 @@ class Article * @param $content string Inhalt des Beitrags * @param $author string der Autor des des Beitrages NID * @param $category string Kategorie des Beitrages - * @param $date + * @param $creationDate * @param $tags string[] optionale Schlagworte für eine bessere Suche */ - public function __construct($id, $title, $content, $author, $date, $category, array $tags) + public function __construct($id, $title, $content, $author, $creationDate, $category, array $tags) { $this->id = $id; $this->title = $title; $this->content = $content; $this->author = $author; - $this->date = $date; + $this->creationDate = $creationDate; $this->category = $category; $this->tags = $tags; } @@ -98,9 +98,9 @@ class Article * Gibt das Veröffentlichungsdatum des Artikels zurück. * @return mixed */ - public function getDate() + public function getcreationDate() { - return $this->date; + return $this->creationDate; } } diff --git a/php/model/ArticleManager.php b/php/model/ArticleManager.php index f7bcec3..f1dbac4 100644 --- a/php/model/ArticleManager.php +++ b/php/model/ArticleManager.php @@ -1,84 +1,18 @@ file, - json_encode($articles, JSON_PRETTY_PRINT) - ); - - } - - public function addArticle($title, $content, $author, $category, array $tags) - { - $articles = $this->getAllArticles(); - - $articles[] = [ - "id" => count($articles)+1, - "title" => $title, - "content" => $content, - "author" => $author, - "category" => $category, - "tags" => $tags - ]; - - $this->saveArticle($articles); - } - - public function updateArticle($id, $title, $content, $author) - { - // TODO: Implement updateArticle() method. - } - - public function deleteArticle($id) - { - // TODO: Implement deleteArticle() method. - } - - public function getArticle($id) - { - // TODO: Implement getArticle() method. - } - - public function getAllArticles() - { - if (!file_exists($this->file)) { - return []; - } - - $json = file_get_contents($this->file); - $articles = json_decode($json, true); - - return is_array($articles) ? $articles : []; - } - -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/php/model/ArticleManagerDAO.php b/php/model/ArticleManagerDAO.php index e8e64d7..ac01ce4 100644 --- a/php/model/ArticleManagerDAO.php +++ b/php/model/ArticleManagerDAO.php @@ -1,10 +1,9 @@ file, + json_encode($articles, JSON_PRETTY_PRINT) + ); + + } + + public function addArticle($title, $content, $author, $category, array $tags) + { + $articles = $this->getAllArticles(); + + $articles[] = [ + "id" => count($articles)+1, + "title" => $title, + "content" => $content, + "author" => $author, + "category" => $category, + "tags" => $tags, + "creationDate" => date("Y-m-d H:i:s") + ]; + + $this->saveArticle($articles); + } + + public function updateArticle($id, $title, $content, $author) + { + // TODO: Implement updateArticle() method. + } + + public function deleteArticle($id) + { + // TODO: Implement deleteArticle() method. + } + + public function getArticle($id) + { + // TODO: Implement getArticle() method. + } + + public function getAllArticles() + { + if (!file_exists($this->file)) { + return []; + } + + $json = file_get_contents($this->file); + $articles = json_decode($json, true); + + return is_array($articles) ? $articles : []; + } + +} +?> \ No newline at end of file