فهرست منبع

Merge pull request #1890 from visuddhinanda/laravel

add render_qa
visuddhinanda 2 سال پیش
والد
کامیت
ce33d0370b
2فایلهای تغییر یافته به همراه54 افزوده شده و 1 حذف شده
  1. 53 0
      app/Http/Api/TemplateRender.php
  2. 1 1
      app/Http/Controllers/DiscussionController.php

+ 53 - 0
app/Http/Api/TemplateRender.php

@@ -10,6 +10,8 @@ use App\Models\DhammaTerm;
 use App\Models\PaliText;
 use App\Models\PaliText;
 use App\Models\Channel;
 use App\Models\Channel;
 use App\Models\PageNumber;
 use App\Models\PageNumber;
+use App\Models\Discussion;
+
 use App\Http\Controllers\CorpusController;
 use App\Http\Controllers\CorpusController;
 
 
 use App\Tools\RedisClusters;
 use App\Tools\RedisClusters;
@@ -84,6 +86,9 @@ class TemplateRender{
             case 'mermaid':
             case 'mermaid':
                 $result = $this->render_mermaid();
                 $result = $this->render_mermaid();
                 break;
                 break;
+            case 'qa':
+                $result = $this->render_qa();
+                break;
             default:
             default:
                 # code...
                 # code...
                 $result = [
                 $result = [
@@ -459,6 +464,8 @@ class TemplateRender{
         $title = $this->get_param($this->param,"title",3);
         $title = $this->get_param($this->param,"title",3);
         $channel = $this->get_param($this->param,"channel",4,$this->channel_id[0]);
         $channel = $this->get_param($this->param,"channel",4,$this->channel_id[0]);
         $style = $this->get_param($this->param,"style",5);
         $style = $this->get_param($this->param,"style",5);
+        $book = $this->get_param($this->param,"book",6);
+        $paragraphs = $this->get_param($this->param,"paragraphs",7);
         $props = [
         $props = [
                     "type" => $type,
                     "type" => $type,
                     "id" => $id,
                     "id" => $id,
@@ -468,6 +475,12 @@ class TemplateRender{
         if(!empty($title)){
         if(!empty($title)){
             $props['title'] = $title;
             $props['title'] = $title;
         }
         }
+        if(!empty($book)){
+            $props['book'] = $book;
+        }
+        if(!empty($paragraphs)){
+            $props['paragraphs'] = $paragraphs;
+        }
         switch ($this->format) {
         switch ($this->format) {
             case 'react':
             case 'react':
                 $output = [
                 $output = [
@@ -855,6 +868,46 @@ class TemplateRender{
         return $output;
         return $output;
     }
     }
 
 
+    private  function render_qa(){
+
+        $id = $this->get_param($this->param,"id",2);
+        $style = $this->get_param($this->param,"style",5);
+
+        $props = [
+                    "type" => 'qa',
+                    "id" => $id,
+                    'title' => '',
+                    'style' => $style,
+                ];
+        $qa = Discussion::where('id',$id)->first();
+        if($qa){
+            $props['title'] = $qa->title;
+            $props['resId'] = $qa->res_id;
+            $props['resType'] = $qa->res_type;
+        }
+
+        switch ($this->format) {
+            case 'react':
+                $output = [
+                    'props'=>base64_encode(\json_encode($props)),
+                    'html'=>"",
+                    'text'=>$props['title'],
+                    'tag'=>'div',
+                    'tpl'=>'qa',
+                    ];
+                break;
+            case 'unity':
+                $output = [
+                    'props'=>base64_encode(\json_encode($props)),
+                    'tpl'=>'qa',
+                    ];
+                break;
+            default:
+                $output = $props['title'];
+                break;
+        }
+        return $output;
+    }
     private  function get_param(array $param,string $name,int $id,string $default=''){
     private  function get_param(array $param,string $name,int $id,string $default=''){
         if(isset($param[$name])){
         if(isset($param[$name])){
             return trim($param[$name]);
             return trim($param[$name]);

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

@@ -69,7 +69,7 @@ class DiscussionController extends Controller
                  */
                  */
                 $roots = Discussion::where('res_id',$request->get('id'))
                 $roots = Discussion::where('res_id',$request->get('id'))
                                     ->where('type', $request->get('type','discussion'))
                                     ->where('type', $request->get('type','discussion'))
-                                    ->where('status',$request->get('status','active'))
+                                    ->whereIn('status',explode(',',$request->get('status','active')) )
                                     ->where('parent',null)
                                     ->where('parent',null)
                                     ->select('id')
                                     ->select('id')
                                     ->get();
                                     ->get();