Forum implementiert #34

Merged
niklas.ortmann merged 20 commits from Forum into dev 2026-06-17 10:24:25 +02:00
Showing only changes of commit 7694396454 - Show all commits
+45 -29
View File
@@ -3,11 +3,28 @@ include_once 'php/controller/showArticle-controller.php';
require_once 'php/model/CommentManager.php';
$comments = [];
$mainComments = [];
$repliesByParent = [];
if (isset($_GET["id"])) {
try {
$commentManager = CommentManager::getInstance();
caroline.slt marked this conversation as resolved Outdated
Outdated
Review

Warum wurde der Kommentar entfernt?

Warum wurde der Kommentar entfernt?
$comments = $commentManager->getCommentsByArticle($_GET["id"]);
foreach ($comments as $comment) {
if ($comment->isReply()) {
$parentId = $comment->getParentCommentId();
if (!isset($repliesByParent[$parentId])) {
$repliesByParent[$parentId] = [];
}
$repliesByParent[$parentId][] = $comment;
} else {
$mainComments[] = $comment;
}
}
} catch (Exception $e) {
$_SESSION["message"] = "internal_error";
}
@@ -26,7 +43,7 @@ if (isset($_GET["id"])) {
</p>
<?php endif; ?>
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_id"): ?>
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_id"): ?>
<p class="alert-message is-error">
Es ist ein Fehler aufgetreten. Die ID konnte nicht ausgelesen werden. Bitte versuche es erneut.
</p>
@@ -102,40 +119,38 @@ if (isset($_GET["id"])) {
<h2>Kommentare</h2>
<div id="comments-list">
<?php if (!empty($comments)): ?>
<?php foreach ($comments as $comment): ?>
<?php if (!$comment->isReply()): ?>
<div class="comment-item" data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>">
<p>
<strong><?php echo htmlspecialchars($comment->getAuthor()); ?></strong>
<span><?php echo htmlspecialchars($comment->getCreated()); ?></span>
</p>
<?php if (!empty($mainComments)): ?>
<?php foreach ($mainComments as $comment): ?>
<div class="comment-item" data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>">
<p>
<strong><?php echo htmlspecialchars($comment->getAuthor()); ?></strong>
<span><?php echo htmlspecialchars($comment->getCreated()); ?></span>
</p>
<p><?php echo nl2br(htmlspecialchars($comment->getContent())); ?></p>
<p><?php echo nl2br(htmlspecialchars($comment->getContent())); ?></p>
<button type="button"
class="reply-button"
data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>"
data-author="<?php echo htmlspecialchars($comment->getAuthor()); ?>">
Antworten
</button>
<button type="button"
class="reply-button"
data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>"
data-author="<?php echo htmlspecialchars($comment->getAuthor()); ?>">
Antworten
</button>
<div class="comment-replies">
<?php foreach ($comments as $reply): ?>
<?php if ($reply->getParentCommentId() === $comment->getId()): ?>
<div class="comment-item comment-reply">
<p>
<strong><?php echo htmlspecialchars($reply->getAuthor()); ?></strong>
<span><?php echo htmlspecialchars($reply->getCreated()); ?></span>
</p>
<div class="comment-replies">
<?php if (isset($repliesByParent[$comment->getId()])): ?>
<?php foreach ($repliesByParent[$comment->getId()] as $reply): ?>
<div class="comment-item comment-reply">
<p>
<strong><?php echo htmlspecialchars($reply->getAuthor()); ?></strong>
<span><?php echo htmlspecialchars($reply->getCreated()); ?></span>
</p>
<p><?php echo nl2br(htmlspecialchars($reply->getContent())); ?></p>
</div>
<?php endif; ?>
<p><?php echo nl2br(htmlspecialchars($reply->getContent())); ?></p>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php else: ?>
<p class="no-comments-message">
@@ -149,6 +164,7 @@ if (isset($_GET["id"])) {
<input type="hidden"
name="article_id"
value="<?php echo htmlspecialchars($_GET["id"] ?? ""); ?>">
<input type="hidden"
name="parent_comment_id"
id="parent-comment-id"