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