Antwortmöglichkeit
This commit is contained in:
+45
-29
@@ -3,11 +3,28 @@ include_once 'php/controller/showArticle-controller.php';
|
|||||||
require_once 'php/model/CommentManager.php';
|
require_once 'php/model/CommentManager.php';
|
||||||
|
|
||||||
$comments = [];
|
$comments = [];
|
||||||
|
$mainComments = [];
|
||||||
|
$repliesByParent = [];
|
||||||
|
|
||||||
if (isset($_GET["id"])) {
|
if (isset($_GET["id"])) {
|
||||||
try {
|
try {
|
||||||
$commentManager = CommentManager::getInstance();
|
$commentManager = CommentManager::getInstance();
|
||||||
$comments = $commentManager->getCommentsByArticle($_GET["id"]);
|
$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) {
|
} catch (Exception $e) {
|
||||||
$_SESSION["message"] = "internal_error";
|
$_SESSION["message"] = "internal_error";
|
||||||
}
|
}
|
||||||
@@ -26,7 +43,7 @@ if (isset($_GET["id"])) {
|
|||||||
</p>
|
</p>
|
||||||
<?php endif; ?>
|
<?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">
|
<p class="alert-message is-error">
|
||||||
Es ist ein Fehler aufgetreten. Die ID konnte nicht ausgelesen werden. Bitte versuche es erneut.
|
Es ist ein Fehler aufgetreten. Die ID konnte nicht ausgelesen werden. Bitte versuche es erneut.
|
||||||
</p>
|
</p>
|
||||||
@@ -102,40 +119,38 @@ if (isset($_GET["id"])) {
|
|||||||
<h2>Kommentare</h2>
|
<h2>Kommentare</h2>
|
||||||
|
|
||||||
<div id="comments-list">
|
<div id="comments-list">
|
||||||
<?php if (!empty($comments)): ?>
|
<?php if (!empty($mainComments)): ?>
|
||||||
<?php foreach ($comments as $comment): ?>
|
<?php foreach ($mainComments as $comment): ?>
|
||||||
<?php if (!$comment->isReply()): ?>
|
<div class="comment-item" data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>">
|
||||||
<div class="comment-item" data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>">
|
<p>
|
||||||
<p>
|
<strong><?php echo htmlspecialchars($comment->getAuthor()); ?></strong>
|
||||||
<strong><?php echo htmlspecialchars($comment->getAuthor()); ?></strong>
|
<span><?php echo htmlspecialchars($comment->getCreated()); ?></span>
|
||||||
<span><?php echo htmlspecialchars($comment->getCreated()); ?></span>
|
</p>
|
||||||
</p>
|
|
||||||
|
|
||||||
<p><?php echo nl2br(htmlspecialchars($comment->getContent())); ?></p>
|
<p><?php echo nl2br(htmlspecialchars($comment->getContent())); ?></p>
|
||||||
|
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="reply-button"
|
class="reply-button"
|
||||||
data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>"
|
data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>"
|
||||||
data-author="<?php echo htmlspecialchars($comment->getAuthor()); ?>">
|
data-author="<?php echo htmlspecialchars($comment->getAuthor()); ?>">
|
||||||
Antworten
|
Antworten
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="comment-replies">
|
<div class="comment-replies">
|
||||||
<?php foreach ($comments as $reply): ?>
|
<?php if (isset($repliesByParent[$comment->getId()])): ?>
|
||||||
<?php if ($reply->getParentCommentId() === $comment->getId()): ?>
|
<?php foreach ($repliesByParent[$comment->getId()] as $reply): ?>
|
||||||
<div class="comment-item comment-reply">
|
<div class="comment-item comment-reply">
|
||||||
<p>
|
<p>
|
||||||
<strong><?php echo htmlspecialchars($reply->getAuthor()); ?></strong>
|
<strong><?php echo htmlspecialchars($reply->getAuthor()); ?></strong>
|
||||||
<span><?php echo htmlspecialchars($reply->getCreated()); ?></span>
|
<span><?php echo htmlspecialchars($reply->getCreated()); ?></span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p><?php echo nl2br(htmlspecialchars($reply->getContent())); ?></p>
|
<p><?php echo nl2br(htmlspecialchars($reply->getContent())); ?></p>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<p class="no-comments-message">
|
<p class="no-comments-message">
|
||||||
@@ -149,6 +164,7 @@ if (isset($_GET["id"])) {
|
|||||||
<input type="hidden"
|
<input type="hidden"
|
||||||
name="article_id"
|
name="article_id"
|
||||||
value="<?php echo htmlspecialchars($_GET["id"] ?? ""); ?>">
|
value="<?php echo htmlspecialchars($_GET["id"] ?? ""); ?>">
|
||||||
|
|
||||||
<input type="hidden"
|
<input type="hidden"
|
||||||
name="parent_comment_id"
|
name="parent_comment_id"
|
||||||
id="parent-comment-id"
|
id="parent-comment-id"
|
||||||
|
|||||||
Reference in New Issue
Block a user