diff --git a/content/showArticle.php b/content/showArticle.php index dbd4082..0038341 100644 --- a/content/showArticle.php +++ b/content/showArticle.php @@ -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(); $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"])) {
- + @@ -102,40 +119,38 @@ if (isset($_GET["id"])) {
- getAuthor()); ?> - getCreated()); ?> -
+ + ++ getAuthor()); ?> + getCreated()); ?> +
-getContent())); ?>
+getContent())); ?>
- + -- getAuthor()); ?> - getCreated()); ?> -
++ getAuthor()); ?> + getCreated()); ?> +
-getContent())); ?>
-getContent())); ?>
+