فهرست منبع

Merge pull request #1789 from visuddhinanda/laravel

支持段落链接
visuddhinanda 2 سال پیش
والد
کامیت
a96baebf40

+ 119 - 0
app/Console/Commands/UpgradeWbwParaNum.php

@@ -0,0 +1,119 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Models\WbwTemplate;
+
+class UpgradeWbwParaNum extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *  php artisan upgrade:wbw.para.num 130
+     * @var string
+     */
+    protected $signature = 'upgrade:wbw.para.num {book?}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Command description';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        if(empty($this->argument('book'))){
+            $start = 1;
+            $end = 217;
+        }else{
+            $start = $this->argument('book');
+            $end = $this->argument('book');
+        }
+
+        for ($iBook=$start; $iBook <=$end ; $iBook++) {
+            $this->info("book = {$iBook}");
+
+            $startAt = time();
+            $count = WbwTemplate::where('book',$iBook)->count();
+            $bar = $this->output->createProgressBar($count);
+            $rows = WbwTemplate::where('book',$iBook)
+                                ->orderBy('paragraph')
+                                ->orderBy('wid')->cursor();
+            $start = false;
+            $bookCode='';
+            $count=0;
+            $currPara = 0;
+            $bookCodeStack = [];
+            foreach ($rows as $key => $row) {
+                $bar->advance();
+                if($row->paragraph !== $currPara){
+                    $currPara = $row->paragraph;
+                    $start = false;
+                    $bookCode='';
+                    $bookCodeStack = [];
+                }
+                if($row->word==='('){
+                    $start = true;
+                    $bookCode='';
+                    $bookCodeStack = [];
+                    continue;
+                }
+                if($start){
+                    if(is_numeric(str_replace('-','',$row->word))){
+                        if(empty($bookCode) && count($bookCodeStack)>0){
+                            //继承之前的
+                            $bookCodeList=[];
+                            foreach ($bookCodeStack as $key => $value) {
+                                $bookCodeList[] = $key;
+                            }
+                            $bookCode = $bookCodeList[0];
+                        }
+                        $dot = mb_strrpos($bookCode,'.',0,'UTF-8');
+                        if($dot === false){
+                            $bookName = $bookCode;
+                            $paraNum = $row->word;
+                        }else{
+                            $bookName = mb_substr($bookCode,0,$dot+1,'UTF-8');
+                            $paraNum = mb_substr($bookCode,$dot+1,null,'UTF-8').$row->word;
+                        }
+                        $bookCodeStack[$bookName] = 1;
+                        WbwTemplate::where('id',$row->id)->update([
+                            'type'=>':cs.para:',
+                            'gramma'=>mb_strtolower(mb_substr($bookName,0,64,'UTF-8'),'UTF-8'),
+                            'part'=>$paraNum,
+                        ]);
+                        $count++;
+                    }else if($row->word===';'){
+                        $bookCode = '';
+                        continue;
+                    }else if($row->word===')'){
+                        $start = false;
+                        continue;
+                    }
+                    $bookCode .= $row->word;
+                }
+            }
+            $bar->finish();
+            $time = time() - $startAt;
+            $this->info(" {$time}s {$count}");
+        }
+
+        return 0;
+    }
+}

+ 13 - 12
app/Http/Api/BookTitle.php

@@ -2521,30 +2521,30 @@ class BookTitle{
     "id" => 183,
     "book" => 164,
     "name" => "Mūlapaṇṇāsapāḷi",
-    "term" => "majimanikaya",
-    "v_title" => "majimanikaya",
-    "m_title" => "majimanikaya",
-    "p_title" => "majimanikaya",
+    "term" => "majjhimanikaya",
+    "v_title" => "majjhimanikaya",
+    "m_title" => "majjhimanikaya",
+    "p_title" => "majjhimanikaya",
     "abbr" => "ma."
   ],
   [
     "id" => 184,
     "book" => 165,
     "name" => "Majjhimapaṇṇāsapāḷi",
-    "term" => "majimanikaya",
-    "v_title" => "majimanikaya",
-    "m_title" => "majimanikaya",
-    "p_title" => "majimanikaya",
+    "term" => "majjhimanikaya",
+    "v_title" => "majjhimanikaya",
+    "m_title" => "majjhimanikaya",
+    "p_title" => "majjhimanikaya",
     "abbr" => "ma."
   ],
   [
     "id" => 185,
     "book" => 166,
     "name" => "Uparipaṇṇāsapāḷi",
-    "term" => "majimanikaya",
-    "v_title" => "majimanikaya",
-    "m_title" => "majimanikaya",
-    "p_title" => "majimanikaya",
+    "term" => "majjhimanikaya",
+    "v_title" => "majjhimanikaya",
+    "m_title" => "majjhimanikaya",
+    "p_title" => "majjhimanikaya",
     "abbr" => "ma."
   ],
   [
@@ -3510,5 +3510,6 @@ class BookTitle{
   ];
 
 
+
     }
 }

+ 110 - 0
app/Http/Controllers/NavCSParaController.php

@@ -0,0 +1,110 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\WbwTemplate;
+use App\Models\PaliText;
+use App\Models\RelatedParagraph;
+use App\Http\Resources\NavCSParaResource;
+use Illuminate\Http\Request;
+
+class NavCSParaController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\WbwTemplate  $wbwTemplate
+     * @return \Illuminate\Http\Response
+     */
+    public function show(string $paraNumber)
+    {
+        //99-5-37
+        $id = explode('_',$paraNumber);
+        if(count($id) !== 3){
+            return $this->error('参数错误。参数应为3 实际得到'.count($id),400,400);
+        }
+        //查询段落起始
+        $para = PaliText::where('book',$id[0])
+                        ->where('paragraph',$id[1])
+                        ->first();
+        if(!$para){
+            return $this->error('没有找到段落起始'.$id,404,404);
+        }
+        $begin = $id[1];
+        $end = (int)$id[1] + $para->chapter_len;
+        $curr = WbwTemplate::where('book',$id[0])
+                                ->where('style','paranum')
+                                ->where('word',$id[2])
+                                ->whereBetween('paragraph',[$begin,$end])
+                                ->select('book','paragraph')->first();
+        if(!$curr){
+            return $this->error('没有找到段落'.$id,404,404);
+        }
+        $data = [];
+        $data['curr'] = new NavCSParaResource($curr);
+        $next = WbwTemplate::where('book',$id[0])
+                ->where('style','paranum')
+                ->where('word',(int)$id[2]+1)
+                ->whereBetween('paragraph',[$begin,$end])
+                ->select('book','paragraph')->first();
+        if($next){
+            $data['next'] = new NavCSParaResource($next);
+            $data['end'] = $next->paragraph -1;
+        }else{
+            $data['end'] = $end;
+        }
+        $prev = WbwTemplate::where('book',$id[0])
+                            ->where('style','paranum')
+                            ->where('word',$id[2]-1)
+                            ->whereBetween('paragraph',[$begin,$end])
+                            ->select('book','paragraph')->first();
+        if($prev){
+            $data['prev'] = new NavCSParaResource($prev);
+        }
+        return $this->ok($data);
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Models\WbwTemplate  $wbwTemplate
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, WbwTemplate $wbwTemplate)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\WbwTemplate  $wbwTemplate
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(WbwTemplate $wbwTemplate)
+    {
+        //
+    }
+}

+ 26 - 0
app/Http/Resources/NavCSParaResource.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Http\Resources;
+
+use Illuminate\Http\Resources\Json\JsonResource;
+use App\Models\PaliText;
+
+class NavCSParaResource extends JsonResource
+{
+    /**
+     * Transform the resource into an array.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
+     */
+    public function toArray($request)
+    {
+        $data = [];
+        $data['content'] = PaliText::where('book',$this->book)
+                                ->where('paragraph',$this->paragraph)
+                                ->value('text');
+        $data['book'] = $this->book;
+        $data['start'] = $this->paragraph;
+        return $data;
+    }
+}

+ 2 - 0
routes/api.php

@@ -81,6 +81,7 @@ use App\Http\Controllers\BookTitleController;
 use App\Http\Controllers\SystemTermController;
 use App\Http\Controllers\TermExportController;
 use App\Http\Controllers\NavArticleController;
+use App\Http\Controllers\NavCSParaController;
 
 /*
 |--------------------------------------------------------------------------
@@ -216,6 +217,7 @@ Route::group(['prefix' => 'v2'],function(){
     Route::apiResource('search-page-number',SearchPageNumberController::class);
     Route::apiResource('nav-page',NavPageController::class);
     Route::apiResource('nav-article',NavArticleController::class);
+    Route::apiResource('nav-cs-para',NavCSParaController::class);
     Route::apiResource('book-title',BookTitleController::class);
 
     Route::get('download/{type1}/{type2}/{uuid}/{filename}', function ($type1,$type2,$uuid,$filename) {