PaliTextService.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Services;
  3. use App\Models\PaliText;
  4. class PaliTextService
  5. {
  6. public function getParent(int $book, int $para) {}
  7. public function getCurrChapter(int $book, int $para)
  8. {
  9. $paragraph = PaliText::where('book', $book)
  10. ->where('paragraph', '<=', $para)
  11. ->where('level', '<', 8)
  12. ->orderBy('paragraph', 'desc')->first();
  13. if ($paragraph) {
  14. return $paragraph;
  15. } else {
  16. return null;
  17. }
  18. }
  19. public function getBookPara(int $book, int $para)
  20. {
  21. $paragraph = PaliText::where('book', $book)
  22. ->where('paragraph', '<=', $para)
  23. ->where('level', 1)
  24. ->orderBy('paragraph', 'asc')->first();
  25. if ($paragraph) {
  26. return $paragraph;
  27. } else {
  28. return null;
  29. }
  30. }
  31. public function getParaCategoryTags(int $book, int $para)
  32. {
  33. $bookPara = self::getBookPara($book, $para);
  34. return app(TagService::class)->getTagsName($bookPara->uid);
  35. }
  36. public function getParaInfo(int $book, int $para)
  37. {
  38. return PaliText::where('book', $book)
  39. ->where('paragraph', $para)
  40. ->first();
  41. }
  42. public function getParaPathTitle(int $book, int $para)
  43. {
  44. $para = self::getParaInfo($book, $para);
  45. return array_map(function ($item) {
  46. return $item->title;
  47. }, json_decode($para->path));
  48. }
  49. }