public function getCommentById(int $commentId, bool $includeReplyTo = true) : array
{
$comment = $this->db->row('SELECT * FROM hull_blog_comments WHERE commentid = ?', $commentId);
if (empty($comment)) {
return [];
}
$comment['body'] = $this->db->cell('SELECT message FROM hull_blog_comment_versions WHERE comment = ? ORDER BY versionid DESC LIMIT 1', $commentId);
if (!empty($comment['author'])) {
$comment['authorname'] = $this->db->cell('SELECT name FROM hull_blog_authors WHERE authorid = ?', $comment['author']);
}
if (!empty($comment['metadata'])) {
$comment['metadata'] = \json_decode($comment['metadata'], true);
}
if ($includeReplyTo) {
if (!empty($comment['replyto'])) {
$comment['parent'] = $this->getCommentById((int) $comment['replyto'], false);
$comment['blog'] = $this->getBlogPostById((int) $comment['blogpost']);
} else {
$comment['parent'] = null;
$comment['blog'] = $this->getBlogPostById((int) $comment['blogpost']);
}
}
return $comment;
}