From ada97ec5381715750965788e47ef888aaeaf9de5 Mon Sep 17 00:00:00 2001 From: Caroline Schulte Date: Sat, 18 Jul 2026 15:26:13 +0200 Subject: [PATCH 01/11] Kommentare ohne js verfassen --- .idea/dataSources.local.xml | 2 +- content/showArticle.php | 104 +++++++++++++++++--- js/comments.js | 37 ++++--- php/ajax/add-comment.php | 186 ++++++++++++++++++++++++++++++------ 4 files changed, 272 insertions(+), 57 deletions(-) diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml index b341a8a..707e2b3 100644 --- a/.idea/dataSources.local.xml +++ b/.idea/dataSources.local.xml @@ -1,6 +1,6 @@ - + " diff --git a/content/showArticle.php b/content/showArticle.php index aea506c..10c09f0 100644 --- a/content/showArticle.php +++ b/content/showArticle.php @@ -5,6 +5,34 @@ $repliesByParent = []; $articleObj = null; include_once 'php/controller/showArticle-controller.php'; +/* + * Ermittelt, ob ohne JavaScript auf einen Kommentar + * geantwortet werden soll. + */ +$replyTo = filter_input( + INPUT_GET, + "reply_to", + FILTER_VALIDATE_INT +); + +$replyAuthor = null; + +if ($replyTo !== false && $replyTo !== null) { + foreach ($mainComments as $mainComment) { + if ($mainComment->getId() === $replyTo) { + $replyAuthor = $mainComment->getAuthor(); + break; + } + } +} + +/* + * Eine Antwort darf nur auf einen existierenden + * Hauptkommentar geschrieben werden. + */ +if ($replyAuthor === null) { + $replyTo = null; +} ?>
-
-
@@ -106,9 +132,24 @@ include_once 'php/controller/showArticle-controller.php';
-
+

Kommentare

+ +
"> + +
+ + + +
@@ -121,12 +162,22 @@ include_once 'php/controller/showArticle-controller.php';

getContent())); ?>

- +
@@ -153,17 +204,46 @@ include_once 'php/controller/showArticle-controller.php';
-
+ + "> + value=""> + value=""> - +

+ style="display: none;" + > + + + Antwort auf + + &id=#comment-form"> + Abbrechen + + +

+ + + + +
+
- getCreated()); ?> - + getCreated()); ?> +

@@ -284,6 +325,48 @@ if ($replyAuthor === null) { && $_SESSION["user_email"] === $reply->getAuthor() ): ?> +

+ + Antwort bearbeiten + + + + + + + + + + + + + + +
+
diff --git a/index.php b/index.php index 3fc2548..91515f7 100644 --- a/index.php +++ b/index.php @@ -39,8 +39,8 @@ if ($pfad === "deleteAccount") { include_once "php/controller/deleteAccount-controller.php"; exit(); } -if ($pfad === "deleteComment") { - include_once "php/controller/deleteComment-controller.php"; +if ($pfad === "updateComment") { + include_once "php/controller/updateComment-controller.php"; exit(); } ?> diff --git a/php/controller/updateComment-controller.php b/php/controller/updateComment-controller.php new file mode 100644 index 0000000..e215911 --- /dev/null +++ b/php/controller/updateComment-controller.php @@ -0,0 +1,92 @@ +updateComment( + $commentId, + $_SESSION["user_email"], + $content + ); + + if ($updated) { + $_SESSION["comment_message"] = + "Der Kommentar wurde erfolgreich bearbeitet."; + + $_SESSION["comment_message_type"] = "success"; + } else { + $_SESSION["comment_message"] = + "Der Kommentar konnte nicht bearbeitet werden."; + + $_SESSION["comment_message_type"] = "error"; + } + +} catch (Throwable $e) { + $_SESSION["comment_message"] = + "Beim Bearbeiten des Kommentars ist ein Fehler aufgetreten."; + + $_SESSION["comment_message_type"] = "error"; +} + +header( + "Location: index.php?pfad=showArticle&id=" + . urlencode((string) $articleId) + . "#comments" +); +exit(); diff --git a/php/model/CommentManagerDAO.php b/php/model/CommentManagerDAO.php index 1390815..518d819 100644 --- a/php/model/CommentManagerDAO.php +++ b/php/model/CommentManagerDAO.php @@ -72,4 +72,19 @@ interface CommentManagerDAO * @return void */ public function deleteCommentsByAuthor(string $author): void; + /** + * Bearbeitet einen Kommentar des angemeldeten Nutzers. + * + * Nur der Autor des Kommentars darf den Inhalt ändern. + * + * @param int $commentId ID des Kommentars + * @param string $author E-Mail-Adresse des Autors + * @param string $content Neuer Kommentarinhalt + * @return bool true, wenn der Kommentar bearbeitet wurde + */ + public function updateComment( + int $commentId, + string $author, + string $content + ): bool; } \ No newline at end of file diff --git a/php/model/DatabaseCommentManager.php b/php/model/DatabaseCommentManager.php index 31bea09..ab9e5aa 100644 --- a/php/model/DatabaseCommentManager.php +++ b/php/model/DatabaseCommentManager.php @@ -223,6 +223,44 @@ class DatabaseCommentManager implements CommentManagerDAO return $comments; } + /** + * Bearbeitet einen eigenen Kommentar. + * + * Der Kommentar wird nur geändert, wenn er dem + * angemeldeten Nutzer gehört. + * + * @param int $commentId ID des Kommentars + * @param string $author E-Mail-Adresse des Autors + * @param string $content Neuer Kommentarinhalt + * @return bool true, wenn der Kommentar bearbeitet wurde + */ + public function updateComment( + int $commentId, + string $author, + string $content + ): bool { + try { + $db = $this->getConnection(); + + $command = $db->prepare(" + UPDATE comments + SET content = :content + WHERE id = :commentId + AND author = :author + "); + + $command->execute([ + ":content" => $content, + ":commentId" => $commentId, + ":author" => $author + ]); + + return $command->rowCount() > 0; + + } catch (PDOException $e) { + throw new RuntimeException("internal_error"); + } + } /** * Löscht einen eigenen Kommentar. * From e3903b4f3e100e4cf9b9f79765e13fcdc48cd637 Mon Sep 17 00:00:00 2001 From: Caroline Schulte Date: Sat, 18 Jul 2026 19:27:36 +0200 Subject: [PATCH 09/11] Kommentare bearbeiten - Fehlerkorrektur --- index.php | 7 ++++++- php/controller/deleteComment-controller.php | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 91515f7..3e5de0f 100644 --- a/index.php +++ b/index.php @@ -34,15 +34,20 @@ if ($pfad === "logout") { include_once "php/controller/logout-controller.php"; exit(); } - if ($pfad === "deleteAccount") { include_once "php/controller/deleteAccount-controller.php"; exit(); } + if ($pfad === "updateComment") { include_once "php/controller/updateComment-controller.php"; exit(); } + +if ($pfad === "deleteComment") { + include_once "php/controller/deleteComment-controller.php"; + exit(); +} ?>