Airship\Cabin\Bridge\Blueprint\Blog::numComments PHP Méthode

numComments() public méthode

Count the number of posts. trinary: NULL -> all posts TRUE -> all published posts FALSE -> all unpublished posts
public numComments ( mixed $published = null ) : integer
$published mixed
Résultat integer
    public function numComments($published = null) : int
    {
        if ($published === null) {
            return (int) $this->db->cell('SELECT count(commentid) FROM hull_blog_comments');
        }
        if ($published) {
            return (int) $this->db->cell('SELECT count(commentid) FROM hull_blog_comments WHERE approved');
        }
        return (int) $this->db->cell('SELECT count(commentid) FROM hull_blog_comments WHERE NOT approved');
    }

Usage Example

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