Ejemplo n.º 1
0
 public static function treeStructure($id = NULL)
 {
     //set root id
     if ($id == NULL) {
         $id = Tree_node::find()->where(['name' => 'TOP'])->one()->id;
     }
     $query = Tree_node::find()->where(['parent_id' => $id, 'hidden' => 0]);
     if (!$query->exists()) {
         return [];
     }
     $nodes = $query->all();
     $tree = [];
     foreach ($nodes as $node) {
         $tree[] = ['name' => $node->name, 'href' => $node->href, 'position' => $node->position, 'list' => Tree_node::treeStructure($node->id)];
     }
     //sort
     $comparator = function ($_a, $_b) {
         $a = $_a['position'];
         $b = $_b['position'];
         if ($a == $b) {
             return 0;
         }
         return $a < $b ? -1 : 1;
     };
     usort($tree, $comparator);
     return $tree;
 }
Ejemplo n.º 2
0
 public function actionIndex($href = "home")
 {
     $node = Tree_node::find()->where(['href' => $href])->one();
     $params = [];
     $params['href'] = $href;
     $params['nav'] = Tree_node::treeStructure();
     $params['breadcrumbs'] = Tree_node::breadcrumbs($href);
     $params['title'] = $node->title;
     $text = $node->text;
     $text = Filters::shortcodeUrls($text);
     $text = Filters::imagesSrc("http://mrt-kt.ru.articles.s3.amazonaws.com/", ".jpg", $text);
     $params['text'] = $text;
     return $this->render('index', $params);
 }