ArticleProgressController.php 3.9 KB

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