public static function getTree($categories, $left = 0, $right = null, $lvl = 1){
$tree = [];
foreach ($categories as $index => $category) {
if ($category->lft >= $left + 1 && (is_null($right) || $category->rgt <= $right) && $category->lvl == $lvl) {
$tree[$index] = [
'id' => $category->id,
'label' => $category->name,
'url' => ['/shop/catalog/list', 'id' => $category->id],
'items' => self::getTree($categories, $category->lft, $category->rgt, $category->lvl + 1),
];
}
}
return $tree;
}
public static function getFullTreeStructure(){
$roots = Category::find()->roots()->addOrderBy('root, lft')->all();
$tree = [];
foreach ($roots as $root){
$tree [] = [
'id' => $root->id,
'label' => $root->name,
'url' => ['/shop/catalog/list', 'id' => $root->id],
'items' => self::getTree($root->children()->all()),
];
}
return $tree;
}