76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php
|
|
require_once DatabaseDAO::class;
|
|
/*
|
|
* Klasse: Eine lokale Lösung der DatenbankDAO.
|
|
* schreibt zunächst Daten lokal in das Verzeichnis und kann diese wieder auslesen.
|
|
*
|
|
* @author Niklas Ortmann
|
|
*/
|
|
class FileDatabase implements DatabaseDAO {
|
|
/*
|
|
* Gibt die Datenbank-Instanz zurück.
|
|
*/
|
|
public static function getInstance()
|
|
{
|
|
if (self::$instance == null) {
|
|
self::$instance = new FileDatabase();
|
|
}
|
|
|
|
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) {
|
|
$newData = array(
|
|
"title" => $title,
|
|
"content" => $content,
|
|
"author" => $author,
|
|
"email" => $_POST["Email"],
|
|
"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.
|
|
}
|
|
|
|
}
|
|
?>
|