diff --git a/php/controller/updateArticle-controller.php b/php/controller/updateArticle-controller.php index 2ffb8b0..d2bcff3 100644 --- a/php/controller/updateArticle-controller.php +++ b/php/controller/updateArticle-controller.php @@ -23,7 +23,12 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") { try { $articleManager = ArticleManager::getInstance(); // TODO: Später aus Session den Nutzer auslesen und Autorenrechte prüfen! - $articleManager->updateArticle(new Article($newTitle, $newContent, $newCategory, $author, $newTags), $author); + $article = $articleManager->getArticle($id); + $article->setTitle($newTitle); + $article->setContent($newContent); + $article->setCategory($newCategory); + $article->setTags($newTags); + $articleManager->updateArticle($id ,$article, $author); } catch (Exception $e){ $_SESSION["message"] = "internal_error"; } diff --git a/php/model/Article.php b/php/model/Article.php index ebb370e..9ffd701 100644 --- a/php/model/Article.php +++ b/php/model/Article.php @@ -1,7 +1,7 @@ category = $category; + } + + /** + * Gibt die Schlagworte eines Beitrags zurück. * @return string */ public function getTags(): string @@ -123,7 +133,7 @@ class Article } /** - * Setzt die Schlagworte eines Artikels. + * Setzt die Schlagworte eines Beitrags. * @param string $tags */ public function setTags(string $tags) diff --git a/php/model/LocalArticleManager.php b/php/model/LocalArticleManager.php index ed37994..7e795f0 100644 --- a/php/model/LocalArticleManager.php +++ b/php/model/LocalArticleManager.php @@ -65,32 +65,36 @@ class LocalArticleManager implements ArticleManagerDAO { public function updateArticle($id, $article, $author) { if (empty($article)) { + // TODO: Implement Exception. return; } // Berechtigungsprüfung: if ($article->getAuthor() !== $author) { - // TODO: Implement Exception (z.B. throw new Exception("Nicht autorisiert")); + // TODO: Implement Exception. return; } + // Beitrag aktualisieren: $articles = $this->getAllArticles(); $updated = false; - // Beitrag aktualisieren: foreach ($articles as $index => $storedArticle) { if (isset($storedArticle['id']) && $storedArticle['id'] == $id) { $articles[$index] = [ "id" => $id, "title" => $article->getTitle(), "content" => $article->getContent(), - "author" => $article->getAuthor(), + "author" => $author, "category" => $article->getCategory(), "tags" => $article->getTags(), - "creationDate" => $article->getCreationDate() // Behält das originale Erstelldatum bei + "creationDate" => $article->getCreationDate() ]; $updated = true; break; + }else{ + // TODO: Implement Exception. + return; } }