public static function getTree($vid, $parentID = false)
    {
        $rows = static::findHierarchy($vid, $parentID);
        $hierarchy = static::indexByChild($rows);

        /** @var Term [] $models */
        $models = Term::find()
            ->indexBy('id')
            ->where(['vid' => $vid])
            ->all();

        //add child to parents by list
        foreach ($hierarchy as $cID => $pID) {
            if (isset($models[$pID]) && isset($models[$cID])) {
                $models[$pID]->addChild($models[$cID]);
            }
        }

        $roots = [];

        foreach ($models as $id => $model) {
            if (isset($hierarchy[$id]) && $hierarchy[$id] == 0) {
                $roots[$id] = $model;
            }
        }

        return isset($models[$parentID]) ? $models[$parentID]->child : $roots;
    }
public static function getTree($vid, $parentID = false)
    {
        $rows = static::findHierarchy($vid, $parentID);
        $hierarchy = static::indexByChild($rows);

        /** @var Term [] $models */
        $models = Term::find()
            ->indexBy('id')
            ->where(['vid' => $vid])
            ->all();

        //add child to parents by list
        foreach ($hierarchy as $cID => $pID) {
            if (isset($models[$pID]) && isset($models[$cID])) {
                $models[$pID]->addChild($models[$cID]);
            }
        }

        $roots = [];

        foreach ($models as $id => $model) {
            if (isset($hierarchy[$id]) && $hierarchy[$id] == 0) {
                $roots[$id] = $model;
            }
        }

        return isset($models[$parentID]) ? $models[$parentID]->child : $roots;
    }
public static function getTree ( $ vid , $ parentID = false ) { $ rows = static :: findHierarchy ( $ vid , $ parentID ) ; $ hierarchy = static :: indexByChild ( $ rows ) ; /** @var Term [] $models */ $ models = Term :: find ( ) -> indexBy ( 'id' ) -> where ( [ 'vid' => $ vid ] ) -> all ( ) ; //add child to parents by list foreach ( $ hierarchy as $ cID => $ pID ) { if ( isset ( $ models [ $ pID ] ) && isset ( $ models [ $ cID ] ) ) { $ models [ $ pID ] -> addChild ( $ models [ $ cID ] ) ; } } $ roots = [ ] ; foreach ( $ models as $ id => $ model ) { if ( isset ( $ hierarchy [ $ id ] ) && $ hierarchy [ $ id ] == 0 ) { $ roots [ $ id ] = $ model ; } } return isset ( $ models [ $ parentID ] ) ? $ models [ $ parentID ] -> child : $ roots ; }
Get tree of terms
@param $vid
@param bool $parentID
@return array
Get tree of terms