Airship\Cabin\Hull\Blueprint\Blog::getCategoryTree PHP Method

getCategoryTree() public method

Get all subcategories for a given category (defaults to root)
public getCategoryTree ( integer $parent ) : array
$parent integer
return array
    public function getCategoryTree(int $parent = 0) : array
    {
        if ($parent === 0) {
            $cats = $this->db->run('SELECT
                    categoryid,
                    name,
                    slug
                FROM
                    hull_blog_categories
                WHERE
                    parent IS NULL
                ORDER BY name ASC
                ');
        } else {
            $cats = $this->db->run('SELECT
                    categoryid,
                    name,
                    slug
                FROM
                    hull_blog_categories
                WHERE
                    parent = ?
                ORDER BY name ASC
                ', $parent);
        }
        if (empty($cats)) {
            return [];
        }
        foreach ($cats as $i => $cat) {
            $cats[$i]['children'] = $this->getCategoryTree((int) $cat['categoryid']);
        }
        return $cats;
    }