updateArticle
This commit is contained in:
@@ -23,7 +23,12 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$articleManager = ArticleManager::getInstance(); // TODO: Später aus Session den Nutzer auslesen und Autorenrechte prüfen!
|
$articleManager = ArticleManager::getInstance(); // TODO: Später aus Session den Nutzer auslesen und Autorenrechte prüfen!
|
||||||
$articleManager->updateArticle(new Article($newTitle, $newContent, $newCategory, $author, $newTags), $author);
|
$article = $articleManager->getArticle($id);
|
||||||
|
$article->setTitle($newTitle);
|
||||||
|
$article->setContent($newContent);
|
||||||
|
$article->setCategory($newCategory);
|
||||||
|
$article->setTags($newTags);
|
||||||
|
$articleManager->updateArticle($id ,$article, $author);
|
||||||
} catch (Exception $e){
|
} catch (Exception $e){
|
||||||
$_SESSION["message"] = "internal_error";
|
$_SESSION["message"] = "internal_error";
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-11
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Klasse: Artikel
|
* Klasse: Artikel
|
||||||
* Diese Klasse stellt alle Daten eines Artikels (Beitrag) bereit
|
* Diese Klasse stellt alle Daten eines Beitrags (Beitrag) bereit
|
||||||
*
|
*
|
||||||
* @author Niklas Ortmann
|
* @author Niklas Ortmann
|
||||||
*/
|
*/
|
||||||
@@ -38,7 +38,7 @@ class Article
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt die ID eines Artikels zurück.
|
* Gibt die ID eines Beitrags zurück.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getId(): int
|
public function getId(): int
|
||||||
@@ -47,7 +47,7 @@ class Article
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt den Titel eines Artikels zurück.
|
* Gibt den Titel eines Beitrags zurück.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
@@ -56,7 +56,7 @@ class Article
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setzt den Titel eines Artikels
|
* Setzt den Titel eines Beitrags
|
||||||
* @param $title
|
* @param $title
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -66,7 +66,7 @@ class Article
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt den Content eines Artikels zurück.
|
* Gibt den Content eines Beitrags zurück.
|
||||||
* TODO: Content muss noch definiert werden.
|
* TODO: Content muss noch definiert werden.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -76,7 +76,7 @@ class Article
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setzt den Content eines Artikels.
|
* Setzt den Content eines Beitrags.
|
||||||
* TODO: Content muss noch definiert werden.
|
* TODO: Content muss noch definiert werden.
|
||||||
* @param $content
|
* @param $content
|
||||||
* @return void
|
* @return void
|
||||||
@@ -87,7 +87,7 @@ class Article
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt den Autor eines Artikels zurück.
|
* Gibt den Autor eines Beitrags zurück.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getAuthor(): string
|
public function getAuthor(): string
|
||||||
@@ -96,7 +96,7 @@ class Article
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt das Veröffentlichungsdatum des Artikels zurück.
|
* Gibt das Veröffentlichungsdatum des Beitrags zurück.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCreationDate(): string
|
public function getCreationDate(): string
|
||||||
@@ -105,7 +105,7 @@ class Article
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt die Kategorie eines Artikels zurück.
|
* Gibt die Kategorie eines Beitrags zurück.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCategory(): string
|
public function getCategory(): string
|
||||||
@@ -114,7 +114,17 @@ class Article
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt die Schlagworte eines Artikels zurück.
|
* Setzt die Kategorie eines Beitrags.
|
||||||
|
* @param string $category
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setCategory(string $category)
|
||||||
|
{
|
||||||
|
$this->category = $category;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die Schlagworte eines Beitrags zurück.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTags(): string
|
public function getTags(): string
|
||||||
@@ -123,7 +133,7 @@ class Article
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setzt die Schlagworte eines Artikels.
|
* Setzt die Schlagworte eines Beitrags.
|
||||||
* @param string $tags
|
* @param string $tags
|
||||||
*/
|
*/
|
||||||
public function setTags(string $tags)
|
public function setTags(string $tags)
|
||||||
|
|||||||
@@ -65,32 +65,36 @@ class LocalArticleManager implements ArticleManagerDAO {
|
|||||||
public function updateArticle($id, $article, $author)
|
public function updateArticle($id, $article, $author)
|
||||||
{
|
{
|
||||||
if (empty($article)) {
|
if (empty($article)) {
|
||||||
|
// TODO: Implement Exception.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Berechtigungsprüfung:
|
// Berechtigungsprüfung:
|
||||||
if ($article->getAuthor() !== $author) {
|
if ($article->getAuthor() !== $author) {
|
||||||
// TODO: Implement Exception (z.B. throw new Exception("Nicht autorisiert"));
|
// TODO: Implement Exception.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Beitrag aktualisieren:
|
||||||
$articles = $this->getAllArticles();
|
$articles = $this->getAllArticles();
|
||||||
$updated = false;
|
$updated = false;
|
||||||
|
|
||||||
// Beitrag aktualisieren:
|
|
||||||
foreach ($articles as $index => $storedArticle) {
|
foreach ($articles as $index => $storedArticle) {
|
||||||
if (isset($storedArticle['id']) && $storedArticle['id'] == $id) {
|
if (isset($storedArticle['id']) && $storedArticle['id'] == $id) {
|
||||||
$articles[$index] = [
|
$articles[$index] = [
|
||||||
"id" => $id,
|
"id" => $id,
|
||||||
"title" => $article->getTitle(),
|
"title" => $article->getTitle(),
|
||||||
"content" => $article->getContent(),
|
"content" => $article->getContent(),
|
||||||
"author" => $article->getAuthor(),
|
"author" => $author,
|
||||||
"category" => $article->getCategory(),
|
"category" => $article->getCategory(),
|
||||||
"tags" => $article->getTags(),
|
"tags" => $article->getTags(),
|
||||||
"creationDate" => $article->getCreationDate() // Behält das originale Erstelldatum bei
|
"creationDate" => $article->getCreationDate()
|
||||||
];
|
];
|
||||||
$updated = true;
|
$updated = true;
|
||||||
break;
|
break;
|
||||||
|
}else{
|
||||||
|
// TODO: Implement Exception.
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user