request->getQuery('page', 'int', 1); $category = $this->getCategoryReadRepository()->getBySlug($categorySlug); $topic = $this->getTopicReadRepository()->getByCategoryIdAndSlug($category['id'], $slug); $comments = $this->getCommentReadRepository() ->findByTopicId( $topic['id'], 10, ($page - 1) * 10 ); $commentIds = []; foreach ($comments as $comment) { $commentIds[] = $comment['id']; } if ($commentIds !== []) { $viewableCommentImages = []; $commentImages = $this->getFileRepository()->findByForumCommentsIds($commentIds); foreach ($commentImages as $commentImage) { $viewableCommentImages[$commentImage->relation_id][] = $commentImage->id; } } $this->renderView([ 'category' => $category, 'topic' => $topic, 'images' => $this->getFileRepository()->findByForumTopicId($topic['id']), 'comments' => $comments, 'commentImages' => $viewableCommentImages ?? [], 'categorySlug' => $categorySlug, 'topicSlug' => $slug, 'page' => $page, 'pages' => ceil($this->getCommentReadRepository()->countByTopicId($topic['id']) / 10), ]); } private function getCategoryReadRepository(): CategoryReadRepository { return new CategoryReadRepository(); } private function getTopicReadRepository(): TopicReadRepository { return new TopicReadRepository(); } private function getFileRepository(): FileRepository { return new FileRepository(); } private function getCommentReadRepository(): CommentReadRepository { return new CommentReadRepository(); } }