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

listPosts() public method

Get the most recent posts
public listPosts ( boolean $showAll = false, integer $offset, integer $limit = 20 ) : array
$showAll boolean
$offset integer
$limit integer
return array
    public function listPosts(bool $showAll = false, int $offset = 0, int $limit = 20) : array
    {
        if ($showAll) {
            // You're an admin, so you get to see non-public information
            $posts = $this->db->run(\Airship\queryString('blog.posts.list_all', ['offset' => $offset, 'limit' => $limit]));
        } else {
            // Only show posts that are public or owned by one of
            // the authors this user belongs to
            $posts = $this->db->safeQuery(\Airship\queryString('blog.posts.list_mine', ['offset' => $offset, 'limit' => $limit]), [\Airship\LensFunctions\userid()]);
        }
        // Always return an array
        if (empty($posts)) {
            return [];
        }
        return $posts;
    }

Usage Example

Example #1
0
 /**
  * List the blog posts
  *
  * @route blog/post{_page}
  * @param string $page
  */
 public function listPosts($page = null)
 {
     list($offset, $limit) = $this->getOffsetAndLimit($page);
     $this->lens('blog/posts', ['active_link' => 'bridge-link-blog-posts', 'blog_posts' => $this->blog->listPosts($this->isSuperUser(), $offset, $limit), 'pagination' => ['base' => $this->airship_cabin_prefix . '/blog/post', 'suffix' => '/', 'count' => $this->blog->numPosts(), 'page' => (int) \ceil($offset / ($limit ?? 1)) + 1, 'per_page' => $limit]]);
 }