Merge branch 'dev' into ImplementedSearch

This commit is contained in:
2026-06-02 14:48:37 +02:00
31 changed files with 1268 additions and 186 deletions
+76 -4
View File
@@ -62,14 +62,65 @@ class LocalArticleManager implements ArticleManagerDAO {
$this->saveArticle($articles);
}
public function updateArticle($id, $title, $content, $author)
public function updateArticle($id, $article, $author)
{
// TODO: Implement updateArticle() method.
if (empty($article)) {
// TODO: Implement Exception.
return;
}
// Berechtigungsprüfung:
if ($article->getAuthor() !== $author) {
// TODO: Implement Exception.
return;
}
// Beitrag aktualisieren:
$articles = $this->getAllArticles();
$updated = false;
foreach ($articles as $index => $storedArticle) {
if (isset($storedArticle['id']) && $storedArticle['id'] == $id) {
$articles[$index] = [
"id" => $id,
"title" => $article->getTitle(),
"content" => $article->getContent(),
"author" => $author,
"category" => $article->getCategory(),
"tags" => $article->getTags(),
"creationDate" => $article->getCreationDate()
];
$updated = true;
break;
}else{
// TODO: Implement Exception.
return;
}
}
// 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)
@@ -97,7 +148,28 @@ class LocalArticleManager implements ArticleManagerDAO {
return is_array($articles) ? $articles : [];
}
public function search(string $keyword): array
public function getArticlesByAuthor($author)
{
$articles = $this->getAllArticles();
$filteredArticles = [];
foreach ($articles as $article) {
if (isset($article['author']) && $article['author'] == $author) {
$filteredArticles[] = new Article(
intval($article['id']),
$article['title'],
$article['content'],
$article['author'],
$article['category'],
$article['tags'],
$article['creationDate']
);
}
}
return $filteredArticles;
}
public function search(string $keyword): array
{
$results = [];
$contentFolder = __DIR__ . '/../content/';