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