Open just-greg-me opened 8 years ago
private static function getTreeInline($categories, $left = 0, $right = null, $lvl = 1){ $names = ''; foreach ($categories as $index => $category) { if ($category->lft >= $left + 1 && (is_null($right) || $category->rgt <= $right) && $category->lvl == $lvl) { $childName = self::getTreeInline($categories, $category->lft, $category->rgt, $category->lvl + 1); $adding = ''; if(!empty($childName)){ $adding = ' - '.$childName; } $names .= $category->name.$adding; } } return $names; } public static function getFullTreeInline(){ $roots = Category::find()->roots()->addOrderBy('root, lft')->all(); $tree = []; foreach ($roots as $root){ $tree [] = [ 'id' => $root->id, 'title' => $root->name.' - '.self::getTreeInline($root->children()->all()), ]; } return $tree; }