TipitakaWordParagraphResource.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use Illuminate\Http\Request;
  4. /**
  5. * 按词形命中的一个三藏段落(`wbw_templates` 按段聚合 + `pali_texts` + `page_numbers`)。
  6. *
  7. * `text` 是整段正文的安全 HTML:只有 `<b>`(原文黑体,即注释书里被解释的词)与 `<mark>`(命中的词形),
  8. * 其余全部已转义,可直接渲染。`refs` 是各印本页码(每种版本取段内第一个),最后一条 `WP` 是 WikiPali
  9. * 段落号;`title` 是丛书缩写(缅甸版、PTS、WP 才有)。
  10. */
  11. class TipitakaWordParagraphResource extends BaseResource
  12. {
  13. /**
  14. * @return array{
  15. * id: string,
  16. * book: int,
  17. * para: int,
  18. * score: int,
  19. * hits: int,
  20. * title: string,
  21. * level: int,
  22. * path: list<array{book: int, para: int, title: string, level: int}>,
  23. * text: string,
  24. * refs: list<array{type: string, volume: int|null, page: int, title: string|null}>
  25. * }
  26. */
  27. public function toArray(Request $request): array
  28. {
  29. return [
  30. 'id' => "{$this['book']}-{$this['para']}",
  31. 'book' => $this['book'],
  32. 'para' => $this['para'],
  33. 'score' => $this['score'],
  34. 'hits' => $this['hits'],
  35. 'title' => $this['title'],
  36. 'level' => $this['level'],
  37. 'path' => $this['path'],
  38. 'text' => $this['text'],
  39. 'refs' => $this['refs'],
  40. ];
  41. }
  42. }