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

numPosts() public method

Count the number of posts. trinary: NULL -> all posts TRUE -> all published posts FALSE -> all unpublished posts
public numPosts ( mixed $published = null ) : integer
$published mixed
return integer
    public function numPosts($published = null) : int
    {
        if ($published === null) {
            return (int) $this->db->cell('SELECT count(postid) FROM hull_blog_posts');
        }
        if ($published) {
            return (int) $this->db->cell('SELECT count(postid) FROM hull_blog_posts WHERE status');
        }
        return (int) $this->db->cell('SELECT count(postid) FROM hull_blog_posts WHERE NOT status');
    }

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]]);
 }