Browse Source

添加义注复注标签

visuddhinanda 2 days ago
parent
commit
7f68e9be7d
1 changed files with 23 additions and 3 deletions
  1. 23 3
      api-v13/app/Http/Controllers/Library/TipitakaController.php

+ 23 - 3
api-v13/app/Http/Controllers/Library/TipitakaController.php

@@ -8,10 +8,12 @@ use Illuminate\Support\Facades\Cookie;
 use Illuminate\Support\Facades\File;
 use Illuminate\Support\Facades\Log;
 
+
 use App\Models\PaliText;
 use App\Models\ProgressChapter;
 use App\Services\TermService;
-
+use App\Models\Tag;
+use App\Models\TagMap;
 
 
 class TipitakaController extends Controller
@@ -118,7 +120,7 @@ class TipitakaController extends Controller
         $selectedSort   = request('sort',   'new');
 
         $sortList = [
-            ['key' => 'new',         'label' => '最新',],
+            ['key' => 'new',         'label' => __('library.badge_updated'),],
             ['key' => 'progress',    'label' => '完成度',],
         ];
 
@@ -336,7 +338,7 @@ class TipitakaController extends Controller
             if (empty($title)) {
                 $title = $pali->firstWhere('book', $book->book)->toc;
             }
-            //Log::debug('getBooksInfo', ['book' => $book->book, 'paragraph' => $book->para]);
+
             $pcd_book_id = $pali->first(function ($item) use ($book) {
                 return $item->book == $book->book
                     && $item->paragraph == $book->para;
@@ -349,11 +351,13 @@ class TipitakaController extends Controller
                 $coverUrl = null;
             }
             $colorIdx = $this->colorIndex($book->uid);
+            $subTitle = $this->getBookType($book->book, $book->para);
 
             $categoryBooks[] = [
                 "id" => $book->uid,
                 "title" => $title,
                 "author" => $book->channel->name,
+                'subTitle' => $subTitle,
                 "publisher" => $book->channel->owner,
                 'completed_chapters' => $book->completed_chapters,
                 "type" => __('labels.' . $book->channel->type),
@@ -365,6 +369,22 @@ class TipitakaController extends Controller
         });
         return $categoryBooks;
     }
+
+
+    private function getBookType(int $book, int $para)
+    {
+
+        $paliTextUuid = PaliText::where('book', $book)->where('paragraph', $para)->value('uid');
+        $tagIds = TagMap::where('anchor_id', $paliTextUuid)->select('tag_id')->get();
+        $tags = Tag::whereIn('id', $tagIds)->select('name')->get();
+        foreach ($tags as $key => $tag) {
+            if (in_array($tag->name, ['pāḷi', 'aṭṭhakathā', 'ṭīkā'])) {
+                return __('library.' . $tag->name);
+            }
+        }
+
+        return null;
+    }
     private function loadCategories()
     {
         $json = file_get_contents(public_path("data/category/default.json"));