Kaynağa Gözat

channelId 改为数组

visuddhinanda 2 yıl önce
ebeveyn
işleme
a185e3c2fe

+ 2 - 2
app/Console/Commands/TestMdRender.php

@@ -76,14 +76,14 @@ class TestMdRender extends Command
         $markdown2 = "aaa=bbb\n";
         $markdown2 .= "ccc=ddd\n";
 */
-        //echo MdRender::render($markdown,'00ae2c48-c204-4082-ae79-79ba2740d506');
+        //echo MdRender::render($markdown,['00ae2c48-c204-4082-ae79-79ba2740d506']);
         //$wiki = MdRender::markdown2wiki($markdown2);
         //$xml = MdRender::wiki2xml($wiki);
         //$html = MdRender::xmlQueryId($xml, "1");
         //$sent = MdRender::take_sentence($html);
         //print_r($sent);
         echo Str::markdown($markdown);
-        echo MdRender::render2($markdown,'00ae2c48-c204-4082-ae79-79ba2740d506',null,'read','nissaya');
+        echo MdRender::render2($markdown,['00ae2c48-c204-4082-ae79-79ba2740d506'],null,'read','nissaya');
         return 0;
     }
 }

+ 5 - 4
app/Http/Api/MdRender.php

@@ -90,7 +90,7 @@ class MdRender{
         }
         return $output;
     }
-    public static function xml2tpl(string $xml, $channelId="",$mode='read'):string{
+    public static function xml2tpl(string $xml, $channelId=[],$mode='read'):string{
         /**
          * 解析xml
          * 获取模版参数
@@ -104,7 +104,7 @@ class MdRender{
             return "<span>xml解析错误{$e}</span>";
         }
 
-        $channelInfo = Channel::find($channelId);
+
 
         $tpl_list = $dom->xpath('//MdTpl');
         foreach ($tpl_list as $key => $tpl) {
@@ -138,6 +138,7 @@ class MdRender{
             /**
              * 生成模版参数
              */
+            $channelInfo = Channel::whereIn('uid',$channelId)->get();
             $tplRender = new TemplateRender($props,$channelInfo,$mode);
             $tplProps = $tplRender->render($tpl_name);
             if($tplProps){
@@ -151,7 +152,7 @@ class MdRender{
         return $html;
     }
 
-    public static function render2($markdown,$channelId='',$queryId=null,$mode='read',$channelType,$contentType="markdown"){
+    public static function render2($markdown,$channelId=[],$queryId=null,$mode='read',$channelType,$contentType="markdown"){
         $wiki = MdRender::markdown2wiki($markdown,$channelType,$contentType);
         $html = MdRender::wiki2xml($wiki);
         if(!is_null($queryId)){
@@ -264,7 +265,7 @@ class MdRender{
     }
 
     /**
-     *
+     * string[] $channelId
      */
     public static function render($markdown,$channelId,$queryId=null,$mode='read',$channelType='translation',$contentType="markdown"){
         return MdRender::render2($markdown,$channelId,$queryId,$mode,$channelType,$contentType);

+ 11 - 9
app/Http/Api/TemplateRender.php

@@ -11,7 +11,7 @@ use App\Http\Api\ChannelApi;
 class TemplateRender{
     protected $param = [];
     protected $mode = "read";
-    protected $channel_id = "";
+    protected $channel_id = [];
 
     /**
      * Create a new command instance.
@@ -21,7 +21,9 @@ class TemplateRender{
     public function __construct($param, $channelInfo, $mode)
     {
         $this->param = $param;
-        $this->channel_id = $channelInfo->uid;
+        foreach ($channelInfo as $value) {
+            $this->channel_id[] = $value->uid;
+        }
         $this->channelInfo = $channelInfo;
         $this->mode = $mode;
     }
@@ -65,9 +67,9 @@ class TemplateRender{
 
     private function render_term(){
         $word = $this->get_param($this->param,"word",1);
-        $channelId = $this->channel_id;
-        $channelInfo = $this->channelInfo;
-        $props = Cache::remember("/term/{$this->channel_id}/{$word}",
+        $channelId = $this->channel_id[0];
+        $channelInfo = $this->channelInfo[0];
+        $props = Cache::remember("/term/{$channelId}/{$word}",
                 env('CACHE_EXPIRE',3600*24),
               function() use($word,$channelId,$channelInfo){
                 //先查属于这个channel 的
@@ -173,7 +175,7 @@ class TemplateRender{
         $props = [
                     "id" => $id,
                     "title" => $title,
-                    "channel" => $this->channel_id,
+                    "channel" => $this->channel_id[0],
                 ];
 
         return [
@@ -188,7 +190,7 @@ class TemplateRender{
         $type = $this->get_param($this->param,"type",1);
         $id = $this->get_param($this->param,"id",2);
         $title = $this->get_param($this->param,"title",3);
-        $channel = $this->get_param($this->param,"channel",4,$this->channel_id);
+        $channel = $this->get_param($this->param,"channel",4,$this->channel_id[0]);
         $style = $this->get_param($this->param,"style",5);
         $props = [
                     "type" => $type,
@@ -208,7 +210,7 @@ class TemplateRender{
     }
     private  function render_quote(){
         $paraId = $this->get_param($this->param,"para",1);
-        $channelId = $this->channel_id;
+        $channelId = $this->channel_id[0];
         $props = Cache::remember("/quote/{$channelId}/{$paraId}",
               env('CACHE_EXPIRE',3600*24),
               function() use($paraId,$channelId){
@@ -247,7 +249,7 @@ class TemplateRender{
         if(!empty($channel)){
             $mChannel = $channel;
         }else{
-            $mChannel = $this->channel_id;
+            $mChannel = $this->channel_id[0];
         }
         $sentInfo = explode('@',trim($sid));
         $sentId = $sentInfo[0];

+ 4 - 4
app/Http/Controllers/CorpusController.php

@@ -285,7 +285,7 @@ class CorpusController extends Controller
                     ->whereIn('channel_uid',$tranChannels)
                     ->first();
         if($title){
-            $this->result['title'] = MdRender::render($title->content,$title->channel_uid);
+            $this->result['title'] = MdRender::render($title->content,[$title->channel_uid]);
         }
 
         /**
@@ -386,7 +386,7 @@ class CorpusController extends Controller
                     ->whereIn('channel_uid',$tranChannels)
                     ->first();
         if($title){
-            $this->result['title'] = MdRender::render($title->content,$title->channel_uid);
+            $this->result['title'] = MdRender::render($title->content,[$title->channel_uid]);
         }
 
         /**
@@ -590,7 +590,7 @@ class CorpusController extends Controller
                             $newSent['html'] = Cache::remember("/sent/{$channelId}/{$currSentId}",
                                                 env('CACHE_EXPIRE',3600*24),
                                                 function() use($row,$mode){
-                                                    return MdRender::render($row->content,$row->channel_uid,null,$mode,"nissaya",$row->content_type);
+                                                    return MdRender::render($row->content,[$row->channel_uid],null,$mode,"nissaya",$row->content_type);
                                                 });
                             break;
                         default:
@@ -598,7 +598,7 @@ class CorpusController extends Controller
                             $newSent['html'] = Cache::remember("/sent/{$channelId}/{$currSentId}",
                                                 env('CACHE_EXPIRE',3600*24),
                                                 function() use($row){
-                                                    return MdRender::render($row->content,$row->channel_uid);
+                                                    return MdRender::render($row->content,[$row->channel_uid]);
                                                 });
                             break;
                     }

+ 1 - 1
app/Http/Controllers/DiscussionController.php

@@ -187,7 +187,7 @@ class DiscussionController extends Controller
                 }
                 $sentId = "{$sent['book']}-{$sent['paragraph']}-{$sent['word_begin']}-{$sent['word_end']}";
                 $channel = $wbwBlock->channel_uid;
-                $content = MdRender::render("{{".$sentId."}}",$channel);
+                $content = MdRender::render("{{".$sentId."}}",[$channel]);
                 return $this->ok($content);
                 break;
 

+ 1 - 1
app/Http/Resources/ArticleResource.php

@@ -107,7 +107,7 @@ class ArticleResource extends JsonResource
             }else{
                 $mode = 'read';
             }
-            $data["html"] = MdRender::render($this->content,$channel,$query_id,$mode);
+            $data["html"] = MdRender::render($this->content,[$channel],$query_id,$mode);
         }
         return $data;
     }

+ 1 - 1
app/Http/Resources/SentPrResource.php

@@ -35,7 +35,7 @@ class SentPrResource extends JsonResource
             "editor"=> StudioApi::getById($this->editor_uid),
             "channel"=> $channel,
             "content"=>$this->content,
-            "html"=> MdRender::render($this->content,$this->channel_uid,null,$mode,$channel['type']),
+            "html"=> MdRender::render($this->content,[$this->channel_uid],null,$mode,$channel['type']),
             "role"=>$role,
             "created_at"=> $this->created_at,
             "updated_at"=> $this->updated_at,

+ 6 - 1
app/Http/Resources/SentResource.php

@@ -39,9 +39,14 @@ class SentResource extends JsonResource
                 "studio" => StudioApi::getById($channel["studio_id"]),
                 "updated_at"=> $this->updated_at,
             ];
+        if($request->has('channels')){
+            $channels = explode(',',$request->get('channels'));
+        }else{
+            $channels = [$this->channel_uid];
+        }
         if($request->get('html',true)){
             $data['html'] = MdRender::render($this->content,
-                                             $this->channel_uid,
+                                             [$this->channel_uid],
                                              null,
                                              $mode,
                                              $channel['type'],