1. PHP / Говнокод #21031

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 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];
    
        }

    Получение дерева каталогов от PHP middle developer

    Запостил: Kilimangaro, 29 Августа 2016

    Комментарии (12) RSS

    Добавить комментарий