Browse Source

添加format参数

visuddhinanda 2 năm trước cách đây
mục cha
commit
fc23261e43
2 tập tin đã thay đổi với 43 bổ sung24 xóa
  1. 3 1
      app/Http/Api/TemplateRender.php
  2. 40 23
      app/Http/Controllers/CorpusController.php

+ 3 - 1
app/Http/Api/TemplateRender.php

@@ -542,7 +542,9 @@ class TemplateRender{
             $channels = [$sentInfo[1]];
         }
         $Sent = new CorpusController();
-        $props = $Sent->getSentTpl($sentId,$channels,$this->mode,true);
+        $props = $Sent->getSentTpl($sentId,$channels,
+                                   $this->mode,true,
+                                   $this->format);
         if($props === false){
             $props['error']="句子模版渲染错误。句子参数个数不符。应该是四个。";
         }

+ 40 - 23
app/Http/Controllers/CorpusController.php

@@ -115,7 +115,7 @@ class CorpusController extends Controller
     {
         //
     }
-    public function getSentTpl($id,$channels,$mode='edit',$onlyProps=false){
+    public function getSentTpl($id,$channels,$mode='edit',$onlyProps=false,$format='react'){
         $sent = [];
         $sentId = \explode('-',$id);
         if(count($sentId) !== 4){
@@ -161,7 +161,7 @@ class CorpusController extends Controller
                 break;
             }
         }
-        return $this->makeContent($record,$mode,$channelIndex,[],$onlyProps);
+        return $this->makeContent($record,$mode,$channelIndex,[],$onlyProps,false,$format);
     }
     /**
      * Display the specified resource.
@@ -554,7 +554,7 @@ class CorpusController extends Controller
      * $indexChannel channel索引
      * $indexedHeading 标题索引 用于给段落加标题标签 <h1> ect.
      */
-    private function makeContent($record,$mode,$indexChannel,$indexedHeading=[],$onlyProps=false,$paraMark=false){
+    private function makeContent($record,$mode,$indexChannel,$indexedHeading=[],$onlyProps=false,$paraMark=false,$format='react'){
         $content = [];
 		$lastSent = "0-0";
 		$sentCount = 0;
@@ -663,19 +663,20 @@ class CorpusController extends Controller
                             // 传过来的数据一定有一个原文channel
                             //
                             if($mode !== "read"){
-
-                                $newSent['channel']['type'] = "wbw";
-
-                                if(isset($this->wbwChannels[0])){
-                                    $newSent['channel']['name'] = $indexChannel[$this->wbwChannels[0]]->name;
-                                    $newSent['channel']['id'] = $this->wbwChannels[0];
-                                    //存在一个translation channel
-                                    //尝试查找逐词解析数据。找到,替换现有数据
-                                    $wbwData = $this->getWbw($arrSentId[0],$arrSentId[1],$arrSentId[2],$arrSentId[3],$this->wbwChannels[0]);
-                                    if($wbwData){
-                                        $newSent['content'] = $wbwData;
-                                        $newSent['contentType'] = 'json';
-                                        $newSent['html'] = "";
+                                if($info->content_type==='json'){
+                                    $newSent['channel']['type'] = "wbw";
+                                    if(isset($this->wbwChannels[0])){
+                                        $newSent['channel']['name'] = $indexChannel[$this->wbwChannels[0]]->name;
+                                        $newSent['channel']['id'] = $this->wbwChannels[0];
+                                        //存在一个translation channel
+                                        //尝试查找逐词解析数据。找到,替换现有数据
+                                        $wbwData = $this->getWbw($arrSentId[0],$arrSentId[1],$arrSentId[2],$arrSentId[3],
+                                                                $this->wbwChannels[0]);
+                                        if($wbwData){
+                                            $newSent['content'] = $wbwData;
+                                            $newSent['contentType'] = 'json';
+                                            $newSent['html'] = "";
+                                        }
                                     }
                                 }
                             }else{
@@ -685,10 +686,12 @@ class CorpusController extends Controller
 
                             break;
                         case 'nissaya':
-                            $newSent['html'] = RedisClusters::remember("/sent/{$channelId}/{$currSentId}",
+                            $newSent['html'] = RedisClusters::remember("/sent/{$channelId}/{$currSentId}/{$format}",
                                                 config('mint.cache.expire'),
-                                                function() use($row,$mode){
-                                                    return MdRender::render($row->content,[$row->channel_uid],null,$mode,"nissaya",$row->content_type);
+                                                function() use($row,$mode,$format){
+                                                    return MdRender::render($row->content,[$row->channel_uid],
+                                                                            null,$mode,"nissaya",
+                                                                            $row->content_type,$format);
                                                 });
                             break;
                         default:
@@ -697,13 +700,27 @@ class CorpusController extends Controller
                          * 包涵术语的不用cache
                          */
                             if(strpos($row->content,'[[')===false){
-                                $newSent['html'] = RedisClusters::remember("/sent/{$channelId}/{$currSentId}",
+                                $newSent['html'] = MdRender::render($row->content,[$row->channel_uid],
+                                                            null,$mode,'translation',
+                                                            $row->content_type,$format);
+                                /*
+                                RedisClusters::remember("/sent/{$channelId}/{$currSentId}/{$format}",
                                                     config('mint.cache.expire'),
-                                                function() use($row){
-                                                    return MdRender::render($row->content,[$row->channel_uid]);
+                                                function() use($row,$mode,$format){
+                                                    return MdRender::render($row->content,[$row->channel_uid],
+                                                                            null,$mode,'translation',
+                                                                            $row->content_type,$format);
                                                 });
+                                            */
                             }else{
-                                $mdRender = new MdRender(['debug'=>$this->debug]);
+                                $mdRender = new MdRender(
+                                    [
+                                        'debug'=>$this->debug,
+                                        'format'=>$format,
+                                        'mode'=>$mode,
+                                        'channelType'=>'translation',
+                                        'contentType'=>$row->content_type,
+                                    ]);
                                 $newSent['html'] = $mdRender->convert($row->content,[$row->channel_uid]);
                             }
                             break;