Airship\Cabin\Bridge\Blueprint\Blog::getCommentById PHP Method

getCommentById() public method

Get a blog comment
public getCommentById ( integer $commentId, boolean $includeReplyTo = true ) : array
$commentId integer
$includeReplyTo boolean Also grab the parent comment?
return array
    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;
    }

Usage Example

Esempio n. 1
0
 /**
  * View a comment
  *
  * @param string $commentId
  * @route blog/comments/view/{id}
  */
 public function viewComment(string $commentId = '')
 {
     $commentId = (int) $commentId;
     $post = $this->post(new CommentFilter());
     if (!empty($post)) {
         switch ($post['comment_btn']) {
             case 'publish':
                 if ($this->can('publish')) {
                     $this->blog->publishComment($commentId);
                 }
                 break;
             case 'hide':
                 if ($this->can('publish')) {
                     $this->blog->hideComment($commentId);
                 }
                 break;
             case 'delete':
                 if ($this->can('delete')) {
                     if ($this->blog->deleteComment($commentId)) {
                         \Airship\redirect($this->airship_cabin_prefix . '/blog/comments');
                     }
                 }
                 break;
         }
     }
     $this->lens('blog/comments_view', ['active_link' => 'bridge-link-blog-comments', 'comment' => $this->blog->getCommentById((int) $commentId)]);
 }