Airship\Cabin\Hull\Blueprint\Blog::getCommentTree PHP Method

getCommentTree() public method

Get all of the blog comments for a given blog post
public getCommentTree ( integer $blogPostId ) : array
$blogPostId integer
return array
    public function getCommentTree(int $blogPostId) : array
    {
        $tree = [];
        $comments = $this->db->run('
            SELECT
              commentid
            FROM
              hull_blog_comments
            WHERE
                blogpost = ?
                AND (replyto IS NULL OR replyto = 0)', $blogPostId);
        foreach ($comments as $com) {
            $data = $this->getCommentWithChildren((int) $com['commentid']);
            if (!empty($data)) {
                $tree[] = $data;
            }
        }
        return $tree;
    }

Usage Example

Example #1
0
 /**
  * @param CacheInterface $cache
  * @param string $uniqueID
  */
 protected function fetchComments(CacheInterface $cache, string $uniqueID)
 {
     $blog = $this->blog->getBlogPostByUniqueId($uniqueID);
     $comments = $this->blog->getCommentTree((int) $blog['postid']);
     $contents = $this->lensRender('blog/comments', ['blogpost' => $blog, 'comments' => $comments, 'config' => $this->config()]);
     $cache->set($uniqueID, ['status' => 'OK', 'cached' => $contents]);
     \Airship\json_response(['status' => 'OK', 'cached' => $contents]);
 }
All Usage Examples Of Airship\Cabin\Hull\Blueprint\Blog::getCommentTree