diff --git a/App/Controllers/NewUi.php b/App/Controllers/NewUi.php index 231b851..9b76648 100644 --- a/App/Controllers/NewUi.php +++ b/App/Controllers/NewUi.php @@ -19,38 +19,9 @@ class NewUi extends Controller $typedocs = $docModel->getAllTypeDocs(); $titles = $docModel->AllTitle(); $groups = $docModel->getGroups(); - $doc_all = $docModel->getArticlesTree(); + $doc_all = $docModel->getArticlesTree(-1); - $mapforbuildtree = []; - $articletree = []; - echo("
");
 
-        foreach ($doc_all as $key => $value){
-            $tmp =  array(
-                'name' => $value['title'],
-                'children' => array(),
-                'id' =>$value['id'],
-                'isParent'=>  false,
-            );
-            $mapforbuildtree[$value['id']] = $tmp;
-        }
-        foreach ($doc_all as $key => $value){
-            if($value['father'] != 0){
-                array_push($mapforbuildtree[$value['father']]['children'],
-                $mapforbuildtree[$value['id']]);
-                $mapforbuildtree[$value['father']]["isParent"] = true;
-
-            }
-        }        
-        foreach ($doc_all as $key => $value){
-            if($value['level'] == 0){
-                array_push($articletree,$mapforbuildtree[$value['id']]);
-           }            
-        }
-
-        $dat = json_encode ( $articletree ,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE );
-        // var_dump($dat);
-        echo("
"); $groupstype = $docModel->GetAllGroupType(); if(sizeof($this->params) == 2){ @@ -84,7 +55,7 @@ class NewUi extends Controller "topdoc"=>$top5, "title"=>"博客", "openapi"=>\App\Config::OpenApiUrl(), - "treedoc"=>$dat, + "treedoc"=>$doc_all, ]); else{ View::renderTemplate("/blog/index.html",[ @@ -100,7 +71,7 @@ class NewUi extends Controller "topdoc"=>$top5, "title"=>"博客", "openapi"=>\App\Config::OpenApiUrl(), - "treedoc"=>$dat, + "treedoc"=>$doc_all, ]); } } @@ -111,18 +82,20 @@ class NewUi extends Controller } $docModel = new Models\Doc(); - $firstpagedocs = []; - $typedocs = $docModel->getAllTypeDocs(); - $doc = $docModel->doc((int)$this->params[0]); - $titles = $docModel->AllTitle(); - $groups = $docModel->getGroups(); - $groupstype = $docModel->GetAllGroupType(); + $doc_all = $docModel->getArticlesTree((int)$this->params[0]); - $fisrtpage = $docModel->pageDoc(5,0,55); - $markdown = new \ParsedownToC(); - $doc[0]['content'] = $markdown->body($doc[0]['content']); - $doc[0]['toc'] = $markdown->contentsList(); - $top5 = $docModel->top5Doc(); + $firstpagedocs = []; + $typedocs = $docModel->getAllTypeDocs(); + $doc = $docModel->doc((int)$this->params[0]); + $titles = $docModel->AllTitle(); + $groups = $docModel->getGroups(); + $groupstype = $docModel->GetAllGroupType(); + + $fisrtpage = $docModel->pageDoc(5,0,55); + $markdown = new \ParsedownToC(); + $doc[0]['content'] = $markdown->body($doc[0]['content']); + $doc[0]['toc'] = $markdown->contentsList(); + $top5 = $docModel->top5Doc(); foreach ($fisrtpage as $key => $value) { $obj['title'] = $value['title']; @@ -152,6 +125,8 @@ class NewUi extends Controller "group_type"=>$docModel->TypeGroup($doc[0]["type"])[0][0], "topdoc"=>$top5, "openapi"=>\App\Config::OpenApiUrl(), + "treedoc"=>$doc_all, + ]); } else{ @@ -172,6 +147,8 @@ class NewUi extends Controller "group_type"=>$docModel->TypeGroup($doc[0]["type"])[0][0], "topdoc"=>$top5, "openapi"=>\App\Config::OpenApiUrl(), + "treedoc"=>$doc_all, + ]); } } @@ -179,9 +156,12 @@ class NewUi extends Controller { if (sizeof($this->querys) != 0) { $docModel = new Models\Doc(); + $commentModel = new Models\DocComment(); $doc = $docModel->titleDoc(rawurldecode($this->querys['title'])); $id = $doc[0]["id"]; + $doc_all = $docModel->getArticlesTree($doc[0]["id"]); + $markdown = new \ParsedownToC(); $doc[0]['content'] = $markdown->body($doc[0]['content']); @@ -211,6 +191,7 @@ class NewUi extends Controller "group_type"=>$docModel->TypeGroup($doc[0]["type"])[0][0], "topdoc"=>$top5, "openapi"=>\App\Config::OpenApiUrl(), + "treedoc"=>$doc_all, ]); else @@ -231,6 +212,8 @@ class NewUi extends Controller "group_type"=>$docModel->TypeGroup($doc[0]["type"])[0][0], "topdoc"=>$top5, "openapi"=>\App\Config::OpenApiUrl(), + "treedoc"=>$doc_all, + ]); } else { View::renderTemplate("/blog/article.html", ['title' => 'test', 'index' => false]); diff --git a/App/Models/Doc.php b/App/Models/Doc.php index d9009ff..d9d0b4e 100644 --- a/App/Models/Doc.php +++ b/App/Models/Doc.php @@ -104,6 +104,15 @@ class Doc extends Model return $recv; } } + public function docTree($id){ + if(is_integer($id)){ + $db = static::getDB(); + $stmt = $db->query('select * from doc_copy1 where id = '.$id); + $recv = $stmt->fetchAll(); + return $recv; + } + } + public function titleDoc($title){ $db = static::getDB(); $stmt = $db->query('select * from doc where title = \''.$title.'\' and doc.is_public = 0'); @@ -134,6 +143,12 @@ class Doc extends Model $result = $stmt->fetchAll(); return $result; } + public function getChildrenDocs($id){ + $db = static::getDB(); + $stmt = $db->query('select * from doc_copy1 where doc_copy1.father = '.$id); + $result = $stmt->fetchAll(); + return $result; + } public function getAllTypeDocs(){ $typedocs = []; $doctypes = $this->getTypes(); @@ -147,12 +162,74 @@ class Doc extends Model } return $typedocs; } - public function getArticlesTree(){ + public function getArticlesTree($opendocid){ $db = static::getDB(); + $mapforbuildtree = []; + $articletree = []; $stmt = $db->query('select id,title,father,level from doc_copy1'); - $result = $stmt->fetchAll(); - return $result; + $doc_all = $stmt->fetchAll(); + foreach ($doc_all as $key => $value){ + $tmp = array( + 'name' => $value['title'], + 'id' =>$value['id'], + 'isParent'=> false, + 'url' => \App\Config::Url() . "ArticleTree/article/" . $value['id']."/".$value['title'], + 'father' => (int)$value['father'], + ); + if($opendocid == $value['father']) + $tmp['open'] = true; + $mapforbuildtree[$value['id']] = $tmp; + + } + foreach ($doc_all as $key => $value){ + if($value['father'] != 0){ + if(!isset($mapforbuildtree[$value['father']]['children'])){ + $mapforbuildtree[$value['father']]['children'] = array(); + } + array_push($mapforbuildtree[$value['father']]['children'], + $mapforbuildtree[$value['id']]); + $mapforbuildtree[$value['father']]["isParent"] = true; + } + } + + $stack = []; + if($opendocid > 0){ + array_push($stack,$opendocid); + // var_dump($mapforbuildtree[$opendocid]); + $fahterid = $mapforbuildtree[$opendocid]['father']; + array_push($stack,$fahterid); + while($fahterid != '0'){ + // var_dump($mapforbuildtree[$fahterid]); + $fahterid = $mapforbuildtree[$fahterid]['father']; + array_push($stack,$fahterid); + } + if(count($stack) > 2) { + $i = count($stack) - 2; + + $tmp = &$mapforbuildtree[$stack[$i]]; + for(;$i > 0;$i--){ + $tmp['open'] = true; + foreach($tmp['children'] as $key => $value){ + if($value['id'] == $stack[$i - 1]){ + $tmp = &$tmp['children'][$key]; + } + } + } + } + // $tmp = $mapforbuildtree[$stack[$i]]; + + } + + + foreach ($doc_all as $key => $value){ + if($value['level'] == 0){ + array_push($articletree,$mapforbuildtree[$value['id']]); + } + } + + $dat = json_encode ( $articletree ,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE ); + return $dat; } public function getAllDocGroup(){ diff --git a/App/Views/blog/article.html b/App/Views/blog/article.html index f4daefb..2516f68 100644 --- a/App/Views/blog/article.html +++ b/App/Views/blog/article.html @@ -13,6 +13,10 @@ + + + + - - - -
-
- -
- -{{ (route) }} -{% if route == "article" %} -{% include '/blog/template/article.html' %} -{% endif %} -{% if route == "donate" %} -{% include '/blog/template/donate.html' %} -{% endif %} -{% if route == "project" %} -{% include '/blog/template/project.html' %} -{% endif %} -{% if route == "data" %} -{% include '/blog/template/data.html' %} -{% endif %} -{% if route == "guide" %} -{% include '/blog/template/guide.html' %} -{% endif %} - - diff --git a/App/Views/blog/css/ztree.css b/App/Views/blog/css/ztree.css index f488e35..99c8dd1 100644 --- a/App/Views/blog/css/ztree.css +++ b/App/Views/blog/css/ztree.css @@ -3,8 +3,8 @@ div.content_wrap div.left{float: left;width: 250px;} div.content_wrap div.right{float: right;width: 340px;} div.zTreeDemoBackground {width:100%;height:100%;text-align:left;} -ul.ztree {margin-top: 10px;border: 1px solid #617775;background: #f0f6e4;width:100%;height:100%;overflow-y:scroll;overflow-x:auto;} -ul.log {border: 1px solid #617775;background: #f0f6e4;width:300px;height:170px;overflow: hidden;} +ul.ztree {margin-top: 10px;width:100%;height:100%;overflow-x:auto;} +ul.log {width:300px;height:170px;overflow: hidden;} ul.log.small {height:45px;} ul.log li {color: #666666;list-style: none;padding-left: 10px;} ul.log li.dark {background-color: #E3E3E3;} diff --git a/App/Views/blog/index.html b/App/Views/blog/index.html index e306b89..31a66c0 100644 --- a/App/Views/blog/index.html +++ b/App/Views/blog/index.html @@ -300,7 +300,6 @@ popNode.style.top = top+"px"; popNode.style.left = left+"px"; document.getElementById("content_table").style.width = width + "px"; - } diff --git a/App/Views/blog/template/articletree.html b/App/Views/blog/template/articletree.html index b7e398f..40af879 100644 --- a/App/Views/blog/template/articletree.html +++ b/App/Views/blog/template/articletree.html @@ -1,66 +1,24 @@ {% block newartile %} @@ -68,7 +26,9 @@
-
    +
      + +