Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create hierarchical Html::Menu() with nested sets? #100

Open
just-greg-me opened this issue Jun 13, 2016 · 1 comment
Open

How to create hierarchical Html::Menu() with nested sets? #100

just-greg-me opened this issue Jun 13, 2016 · 1 comment

Comments

@just-greg-me
Copy link

No description provided.

@just-greg-me
Copy link
Author

just-greg-me commented Jun 17, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant