- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
public static function getTree($version, $lang = 'en')
{
$pt_root = KbTree::findOne(($version == 'pt2') ?
KbTree::NODE_PT2 : KbTree::NODE_PT3);
$list = $pt_root
->children()
->andWhere(['root' => ($version == 'pt2') ? KbTree::NODE_PT2 : KbTree::NODE_PT3])
->andWhere(['visible' => 1, 'pub' => 1])
->orderBy('lft ASC')
->all();
$tree = [$pt_root->id => []];
$currentLevel = 1;
$levelsIds[$currentLevel] = $pt_root->id;
$dic = [];
foreach($list as $key => $_node)
{
if(isset($_node->level, $_node->id))
{
$dic[$_node->id][] = $_node->getTranslateMessage($lang);
$dic[$_node->id][] = $_node->getFullAlias();
$currentLevel = $_node->level;
switch($_node->level) {
case 2:
$tree[$levelsIds[1]][$_node->id] = [];
break;
case 3:
$tree[$levelsIds[1]][$levelsIds[2]][$_node->id] = [];
break;
case 4:
$tree[$levelsIds[1]][$levelsIds[2]][$levelsIds[3]][$_node->id] = [];
break;
case 5:
$tree[$levelsIds[1]][$levelsIds[2]][$levelsIds[3]][$levelsIds[4]][$_node->id] = [];
break;
case 6:
$tree[$levelsIds[1]][$levelsIds[2]][$levelsIds[3]][$levelsIds[4]][$levelsIds[5]][$_node->id] = [];
break;
}
$levelsIds[$currentLevel] = $_node->id;
}
}
return [$tree[$pt_root->id], $dic];
}