refactoring

This commit is contained in:
NOrtmann1
2026-05-26 18:55:42 +02:00
parent d7acca36fd
commit e128a31a34
4 changed files with 39 additions and 22 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ try {
try {
$author = "max.mustermann@web.de"; // wird später aus session bezogen.
$articleManager->newArticle($_POST['post-title'], $_POST['post-content'], $author);
$articleManager->newArticle(new Article()['post-title'], $_POST['post-content'], $author);
} catch (Exception $e) {
echo "Fehler beim Erstellen des Beitrags: " . $e->getMessage();
}
+23 -7
View File
@@ -13,7 +13,23 @@ class Article
private $author;
private $date;
/*
/**
* @param $id integer ID des Beitrages
* @param $title
* @param $content
* @param $author
* @param $date
*/
public function __construct($id, $title, $content, $author, $date)
{
$this->id = $id;
$this->title = $title;
$this->content = $content;
$this->author = $author;
$this->date = $date;
}
/**
* Gibt die ID eines Artikels zurück.
*/
public function getId()
@@ -21,7 +37,7 @@ class Article
return $this->id;
}
/*
/**
* Gibt den Titel eines Artikels zurück.
*/
public function getTitle()
@@ -29,7 +45,7 @@ class Article
return $this->title;
}
/*
/**
* Setzt den Titel eines Artikels.
*/
public function setTitle($title)
@@ -37,7 +53,7 @@ class Article
$this->title = $title;
}
/*
/**
* Gibt den Content eines Artikels zurück.
* TODO: Content muss noch definiert werden.
*/
@@ -46,7 +62,7 @@ class Article
return $this->content;
}
/*
/**
* Setzt den Content eines Artikels.
* TODO: Content muss noch definiert werden.
*/
@@ -55,7 +71,7 @@ class Article
$this->content = $content;
}
/*
/**
* Gibt den Autor eines Artikels zurück.
*/
public function getAuthor()
@@ -63,7 +79,7 @@ class Article
return $this->author;
}
/*
/**
* Gibt das Veröffentlichungsdatum des Artikels zurück.
*/
public function getDate()
+8 -7
View File
@@ -7,7 +7,8 @@ require_once 'ArticleManagerDAO.php';
* @author Niklas Ortmann
*/
class ArticleManager implements ArticleManagerDAO {
/*
/**
* Gibt die Datenbank-Instanz zurück.
*/
public static function getInstance()
@@ -29,13 +30,13 @@ class ArticleManager implements ArticleManagerDAO {
}
public function newArticle($title, $content, $author, $category) {
public function newArticle($article) {
$newData = array(
"title" => $title,
"content" => $content,
"author" => $author,
"category" => $category,
//"tags" => isset($_POST["tags"]) ? $_POST["tags"] : '', TODO: Später hinzufügen
"title" => $article->getTitle(),
"content" => $article->getContent(),
"author" => $article->getAuthor(),
"category" => $article->getCategory(),
//"tags" => $article->getTags(), TODO: Später hinzufügen
"date" => date("d.m.Y, H:i")
);
$newData = base64_encode(serialize($newData));
+7 -7
View File
@@ -1,5 +1,5 @@
<?php
/*
/**
* Die Klasse binhaltet alle Methoden für die Operation auf der Datenbank.
*
* @author Niklas Ortmann
@@ -7,13 +7,13 @@
interface ArticleManagerDAO
{
/*
/**
* Ein angemeldeter Nutzer erstellt einen neuen Beitrag.
* $title Titel des Beitrags
* $content Der Inhalt des Beitrags
* $author dem Author des des Beitrags (NID oder email)
* $category Kategorie des Beitrags
* $tags optionale Schlagworte für eine bessere Suche
* @param $title string Titel des Beitrags
* @param $content string Inhalt des Beitrags
* @param $author string der Autor des des Beitrages NID
* @param $category string Kategorie des Beitrages
* @param $tags string[] optionale Schlagworte für eine bessere Suche
*
* Mögliche Exceptions:
* TODO Fehlerbeschreibung hinzufügen