$comments = $this->comment->getAllPageComments($pageId);
$index = [];
$totalComments = count($comments);
+ $finalCommentList = [];
+
// normalizing the response.
- foreach($comments as &$comment) {
- $comment = $this->normalizeComment($comment);
+ for ($i = 0; $i < count($comments); ++$i) {
+ $comment = $this->normalizeComment($comments[$i]);
$parentId = $comment->parent_id;
if (empty($parentId)) {
+ $finalCommentList[] = $comment;
$index[$comment->id] = $comment;
continue;
}
$index[$comment->id] = $comment;
}
return [
- 'comments' => $comments,
+ 'comments' => $finalCommentList,
'total' => $totalComments
];
}