ArticleManager fehlende Implementationen

This commit is contained in:
NOrtmann1
2026-05-29 18:13:06 +02:00
parent 4a7bfa9567
commit 317f4c0ce9
4 changed files with 205 additions and 19 deletions
+50 -3
View File
@@ -62,14 +62,61 @@ class LocalArticleManager implements ArticleManagerDAO {
$this->saveArticle($articles);
}
public function updateArticle($id, $title, $content, $author)
public function updateArticle($article, $author)
{
// TODO: Implement updateArticle() method.
if (empty($article)) {
return;
}
// Berechtigungsprüfung:
if ($article->getAuthor() !== $author) {
// TODO: Implement Exception (z.B. throw new Exception("Nicht autorisiert"));
return;
}
$articles = $this->getAllArticles();
$updated = false;
// Beitrag aktualisieren:
foreach ($articles as $index => $storedArticle) {
if (isset($storedArticle['id']) && $storedArticle['id'] == $article->getId()) {
$articles[$index] = [
"id" => $article->getId(),
"title" => $article->getTitle(),
"content" => $article->getContent(),
"author" => $article->getAuthor(),
"category" => $article->getCategory(),
"tags" => $article->getTags(),
"creationDate" => $article->getCreationDate() // Behält das originale Erstelldatum bei
];
$updated = true;
break;
}
}
// Nur speichern, wenn Beitrag geändert wurde:
if ($updated) {
$this->saveArticle($articles);
}
}
public function deleteArticle($id)
{
// TODO: Implement deleteArticle() method.
$articles = $this->getAllArticles();
$articleFound = false;
foreach ($articles as $index => $article) {
if (isset($article['id']) && $article['id'] == $id) {
unset($articles[$index]);
$articleFound = true;
break; // Schleife abbrechen, da die ID eindeutig ist
}
}
if ($articleFound) {
// array_values stellt sicher, dass die Array-Keys wieder fortlaufend bei 0 beginnen
$this->saveArticle(array_values($articles));
}
}
public function getArticle($id)