refactoring

This commit is contained in:
NOrtmann1
2026-05-26 18:06:44 +02:00
parent c7f279b7e9
commit 8762bc1b07
6 changed files with 17 additions and 30 deletions
+77
View File
@@ -0,0 +1,77 @@
<?php
require_once 'ArticleManagerDAO.php';
/*
* Klasse: Eine lokale Lösung der DatenbankDAO.
* schreibt zunächst Daten lokal in das Verzeichnis und kann diese wieder auslesen.
*
* @author Niklas Ortmann
*/
class ArticleManager implements ArticleManagerDAO {
/*
* Gibt die Datenbank-Instanz zurück.
*/
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new ArticleManager();
}
return self::$instance;
}
/*
* Prüft, ob die lokalen txt-Dateien existieren.
* Wenn nicht, werden diese erstellt.
*/
public function __construct()
{
}
public function newArticle($title, $content, $author, $category) {
$newData = array(
"title" => $title,
"content" => $content,
"author" => $author,
"category" => $category,
//"tags" => isset($_POST["tags"]) ? $_POST["tags"] : '', TODO: Später hinzufügen
"date" => date("d.m.Y, H:i")
);
$newData = base64_encode(serialize($newData));
if (!file_exists("articles.txt")) {
$newData = fopen("articles.txt", "xb");
fclose($newData);
}
$previousData = file_get_contents("articles.txt");
if (file_put_contents("articles.txt", "$newData\n$previousData")) {
// TODO: Vernünftige Rückmeldung implementieren.
echo "Artikel erfolgreich gespeichert!";
} else {
// TODO: passende Exceptions werfen.
echo "Fehler!";
}
}
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()
{
// TODO: Implement getAllArticles() method.
}
}
?>