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

listComments() public method

List comments
public listComments ( integer $offset, integer $limit = 20 ) : array
$offset integer
$limit integer
return array
    public function listComments(int $offset = 0, int $limit = 20) : array
    {
        $comments = $this->db->run(\Airship\queryString('blog.comments.list_all', ['offset' => $offset, 'limit' => $limit]));
        $bp = [];
        foreach ($comments as $i => $com) {
            if (!\array_key_exists($com['blogpost'], $bp)) {
                $bp[$com['blogpost']] = $this->getBlogPostById((int) $com['blogpost']);
            }
            $comments[$i]['blog'] = $bp[$com['blogpost']];
        }
        if (empty($comments)) {
            return [];
        }
        return $comments;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @route blog/comments{_page}
  * @param string $page
  */
 public function listComments($page = null)
 {
     if (!$this->can('publish')) {
         \Airship\redirect($this->airship_cabin_prefix . '/blog');
     }
     list($offset, $limit) = $this->getOffsetAndLimit($page);
     $this->lens('blog/comments', ['active_link' => 'bridge-link-blog-comments', 'comments' => $this->blog->listComments($offset, $limit), 'pagination' => ['base' => $this->airship_cabin_prefix . '/blog/post', 'suffix' => '/', 'count' => $this->blog->numComments(), 'page' => (int) \ceil($offset / ($limit ?? 1)) + 1, 'per_page' => $limit]]);
 }