public function categories($blogId, $includeCount = true, $onlyPopulated = true)
    {
        $oDb = Factory::service('Database');
        $oDb->select('c.id,c.blog_id,c.slug,c.label');

        if ($includeCount) {

            $sql  = '(SELECT COUNT(DISTINCT bpc.post_id) FROM ' . NAILS_DB_PREFIX . 'blog_post_category bpc JOIN ';
            $sql .= NAILS_DB_PREFIX . 'blog_post bp ON bpc.post_id = bp.id WHERE bpc.category_id = c.id AND ';
            $sql .= 'bp.is_published = 1 AND bp.is_deleted = 0 AND bp.published <= NOW()) post_count';

            $oDb->select($sql);
        }

        if ($onlyPopulated) {

            $oDb->having('post_count > ', 0);
        }

        $oDb->where('c.blog_id', $blogId);
        $oDb->order_by('c.label');

        $categories = $oDb->get(NAILS_DB_PREFIX . 'blog_category c')->result();

        $this->load->model('blog/blog_category_model');

        foreach ($categories as $category) {

            $category->url = $this->blog_category_model->formatUrl($category->slug, $category->blog_id);
        }

        return $categories;
    }
public function categories($blogId, $includeCount = true, $onlyPopulated = true)
    {
        $oDb = Factory::service('Database');
        $oDb->select('c.id,c.blog_id,c.slug,c.label');

        if ($includeCount) {

            $sql  = '(SELECT COUNT(DISTINCT bpc.post_id) FROM ' . NAILS_DB_PREFIX . 'blog_post_category bpc JOIN ';
            $sql .= NAILS_DB_PREFIX . 'blog_post bp ON bpc.post_id = bp.id WHERE bpc.category_id = c.id AND ';
            $sql .= 'bp.is_published = 1 AND bp.is_deleted = 0 AND bp.published <= NOW()) post_count';

            $oDb->select($sql);
        }

        if ($onlyPopulated) {

            $oDb->having('post_count > ', 0);
        }

        $oDb->where('c.blog_id', $blogId);
        $oDb->order_by('c.label');

        $categories = $oDb->get(NAILS_DB_PREFIX . 'blog_category c')->result();

        $this->load->model('blog/blog_category_model');

        foreach ($categories as $category) {

            $category->url = $this->blog_category_model->formatUrl($category->slug, $category->blog_id);
        }

        return $categories;
    }
public function categories ( $ blogId , $ includeCount = true , $ onlyPopulated = true ) { $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> select ( 'c.id,c.blog_id,c.slug,c.label' ) ; if ( $ includeCount ) { $ sql = '(SELECT COUNT(DISTINCT bpc.post_id) FROM ' . NAILS_DB_PREFIX . 'blog_post_category bpc JOIN ' ; $ sql .= NAILS_DB_PREFIX . 'blog_post bp ON bpc.post_id = bp.id WHERE bpc.category_id = c.id AND ' ; $ sql .= 'bp.is_published = 1 AND bp.is_deleted = 0 AND bp.published <= NOW()) post_count' ; $ oDb -> select ( $ sql ) ; } if ( $ onlyPopulated ) { $ oDb -> having ( 'post_count > ' , 0 ) ; } $ oDb -> where ( 'c.blog_id' , $ blogId ) ; $ oDb -> order_by ( 'c.label' ) ; $ categories = $ oDb -> get ( NAILS_DB_PREFIX . 'blog_category c' ) -> result ( ) ; $ this -> load -> model ( 'blog/blog_category_model' ) ; foreach ( $ categories as $ category ) { $ category -> url = $ this -> blog_category_model -> formatUrl ( $ category -> slug , $ category -> blog_id ) ; } return $ categories ; }
Returns an array of a blog's categories
@param  integer $blogId        The ID of the blog to get categories from
@param  boolean $includeCount  Whether to include the post count of each category
@param  boolean $onlyPopulated Whether to remove categories which don't have any posts in them
@return array
Returns an array of a blog s categories