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"])) {

- +

Es ist ein Fehler aufgetreten. Die ID konnte nicht ausgelesen werden. Bitte versuche es erneut.

@@ -102,40 +119,38 @@ if (isset($_GET["id"])) {

Kommentare

- - - isReply()): ?> -
-

- getAuthor()); ?> - getCreated()); ?> -

+ + +
+

+ getAuthor()); ?> + getCreated()); ?> +

-

getContent())); ?>

+

getContent())); ?>

- + -
- - getParentCommentId() === $comment->getId()): ?> -
-

- getAuthor()); ?> - getCreated()); ?> -

+
+ getId()])): ?> + getId()] as $reply): ?> +
+

+ getAuthor()); ?> + getCreated()); ?> +

-

getContent())); ?>

-
- +

getContent())); ?>

+
-
+
- +

@@ -149,6 +164,7 @@ if (isset($_GET["id"])) { "> +