TermService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Services;
  3. use App\Models\DhammaTerm;
  4. use App\Http\Api\ChannelApi;
  5. use App\Http\Resources\TermResource;
  6. class TermService
  7. {
  8. public function getCommunityGlossary($lang)
  9. {
  10. $localTermChannel = ChannelApi::getSysChannel(
  11. "_community_term_" . strtolower($lang) . "_",
  12. "_community_term_en_"
  13. );
  14. $result = DhammaTerm::select(['word', 'tag', 'meaning', 'other_meaning'])
  15. ->where('channal', $localTermChannel)
  16. ->get();
  17. return ['items' => $result, 'total' => count($result)];
  18. }
  19. public function getGrammarGlossary($lang)
  20. {
  21. $localTermChannel = ChannelApi::getSysChannel(
  22. "_System_Grammar_Term_" . strtolower($lang) . "_",
  23. "_System_Grammar_Term_en_"
  24. );
  25. $result = DhammaTerm::select(['word', 'tag', 'meaning', 'other_meaning'])
  26. ->where('channal', $localTermChannel)
  27. ->get();
  28. return ['items' => $result, 'total' => count($result)];
  29. }
  30. public function getRaw($id)
  31. {
  32. $result = DhammaTerm::find($id);
  33. return $result;
  34. }
  35. public function communityTerm(string $word, string $lang)
  36. {
  37. $localTermChannel = ChannelApi::getSysChannel(
  38. "_community_term_" . strtolower($lang) . "_"
  39. );
  40. $result = DhammaTerm::where('word', $word)
  41. ->where('channal', $localTermChannel)
  42. ->first();
  43. if ($result) {
  44. return new TermResource($result);
  45. } else {
  46. return null;
  47. }
  48. }
  49. public function communityTerms(string $lang)
  50. {
  51. $localTermChannel = ChannelApi::getSysChannel(
  52. "_community_term_" . strtolower($lang) . "_"
  53. );
  54. $result = DhammaTerm::where('channal', $localTermChannel)
  55. ->whereNotNull('note')
  56. ->where('note', '<>', '')
  57. ->take(10)
  58. ->orderBy('updated_at', 'desc')
  59. ->get();
  60. return [
  61. "data" => TermResource::collection($result),
  62. "count" => 10
  63. ];
  64. }
  65. }