2
0

ArticleProgressController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Api\PaliTextApi;
  4. use App\Models\Channel;
  5. use App\Models\PaliSentence;
  6. use App\Models\Sentence;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Http\Response;
  9. use Illuminate\Support\Arr;
  10. class ArticleProgressController extends Controller
  11. {
  12. /**
  13. * Display a listing of the resource.
  14. *
  15. * @return Response
  16. */
  17. public function index(Request $request)
  18. {
  19. //
  20. switch ($request->input('view')) {
  21. case 'chapter':
  22. $chapter = PaliTextApi::getChapterStartEnd($request->input('book'), $request->input('para'));
  23. $channels = Sentence::where('book_id', $request->input('book'))
  24. ->whereBetween('paragraph', $chapter)
  25. ->where('strlen', '>', 0)
  26. ->groupBy('channel_uid')
  27. ->select('channel_uid')
  28. ->get();
  29. // 获取单句长度
  30. $sentLen = PaliSentence::where('book', $request->input('book'))
  31. ->whereBetween('paragraph', $chapter)
  32. ->orderBy('word_begin')
  33. ->select(['book', 'paragraph', 'word_begin', 'word_end', 'length'])
  34. ->get();
  35. // 获取每个channel的完成度
  36. foreach ($channels as $key => $value) {
  37. // code...
  38. $finished = Sentence::where('book_id', $request->input('book'))
  39. ->whereBetween('paragraph', $chapter)
  40. ->where('channel_uid', $value->channel_uid)
  41. ->where('strlen', '>', 0)
  42. ->select(['strlen', 'book_id', 'paragraph', 'word_start', 'word_end'])
  43. ->get();
  44. $final = [];
  45. foreach ($sentLen as $sent) {
  46. // code...
  47. $first = Arr::first($finished, function ($value, $key) use ($sent) {
  48. return $value->book_id == $sent->book &&
  49. $value->paragraph == $sent->paragraph &&
  50. $value->word_start == $sent->word_begin &&
  51. $value->word_end == $sent->word_end;
  52. });
  53. $final[] = [$sent->length, $first ? true : false];
  54. }
  55. $value['final'] = $final;
  56. }
  57. return $this->ok($channels);
  58. break;
  59. }
  60. }
  61. /**
  62. * Show the form for creating a new resource.
  63. *
  64. * @return Response
  65. */
  66. public function create()
  67. {
  68. //
  69. }
  70. /**
  71. * Store a newly created resource in storage.
  72. *
  73. * @return Response
  74. */
  75. public function store(Request $request)
  76. {
  77. //
  78. }
  79. /**
  80. * Display the specified resource.
  81. *
  82. * @return Response
  83. */
  84. public function show(Channel $channel)
  85. {
  86. //
  87. }
  88. /**
  89. * Show the form for editing the specified resource.
  90. *
  91. * @return Response
  92. */
  93. public function edit(Channel $channel)
  94. {
  95. //
  96. }
  97. /**
  98. * Update the specified resource in storage.
  99. *
  100. * @return Response
  101. */
  102. public function update(Request $request, Channel $channel)
  103. {
  104. //
  105. }
  106. /**
  107. * Remove the specified resource from storage.
  108. *
  109. * @return Response
  110. */
  111. public function destroy(Channel $channel)
  112. {
  113. //
  114. }
  115. }