visuddhinanda 2 лет назад
Родитель
Сommit
f8399c2b45

+ 78 - 0
app/Http/Controllers/SearchTitleController.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\PaliText;
+use Illuminate\Http\Request;
+use App\Http\Resources\SearchTitleIndexResource;
+
+class SearchTitleController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index(Request $request)
+    {
+        //
+        $key = strtolower($request->get('key'));
+        $table = PaliText::where('level','<',8)
+                         ->where(function ($query) use($key){
+                            $query->where('title_en','like',"%{$key}%")
+                                  ->orWhere('title','like',"%{$key}%");
+                        });
+        $count = $table->count();
+        $table = $table->orderBy('title_en');
+        $table = $table->skip($request->get("offset",0))
+                         ->take($request->get('limit',10));
+
+        $result = $table->get();
+        return $this->ok(["rows"=>SearchTitleIndexResource::collection($result),"count"=>$count]);
+    }
+
+    /**
+     * 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\PaliText  $paliText
+     * @return \Illuminate\Http\Response
+     */
+    public function show(PaliText $paliText)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Models\PaliText  $paliText
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, PaliText $paliText)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\PaliText  $paliText
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(PaliText $paliText)
+    {
+        //
+    }
+}

+ 24 - 0
app/Http/Resources/SearchTitleIndexResource.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Http\Resources;
+
+use Illuminate\Http\Resources\Json\JsonResource;
+
+class SearchTitleIndexResource 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 = [
+            'word'=> $this->text,
+            'count'=> 0,
+            'bold'=> 0,
+        ];
+        return $data;
+    }
+}

+ 31 - 0
app/Http/Resources/SearchTitleResource.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace App\Http\Resources;
+
+use Illuminate\Http\Resources\Json\JsonResource;
+use App\Models\PaliText;
+
+class SearchTitleResource 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 = [
+            "book"=>$this->book,
+            "paragraph"=> $this->paragraph,
+            'content'=>$this->text,
+            'path' => json_decode($this->path),
+            'paliTitle' => $this->toc,
+        ];
+        $data["content"] = PaliText::where('book',$this->book)
+                                            ->where('paragraph',$this->paragraph+1)
+                                            ->value('html');
+        $data["content_type"] = 'html';
+        return $data;
+    }
+}

+ 38 - 0
database/migrations/2023_09_19_014131_add_titleen_in_pali_texts.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddTitleenInPaliTexts extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('pali_texts', function (Blueprint $table) {
+            //
+            $table->text('title_en')->nullable()->index();
+            $table->text('title')->nullable()->index();
+            $table->integer('pcd_book_id')->index()->default(0);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('pali_texts', function (Blueprint $table) {
+            //
+            $table->dropColumn('title_en');
+            $table->dropColumn('title');
+            $table->dropColumn('pcd_book_id');
+        });
+    }
+}