2
0

RelatedParagraphController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /*
  3. *查询相关联的书
  4. *mula->attakhata->tika
  5. *算法:
  6. *在原始的html 文件里 如 s0404m1.mul.htm 有 <a name="para2_an8"></a>
  7. * 在 so404a.att.htm 里也有 </a><a name="para2_an8"></a>
  8. * 这说明这两个段落是关联段落,para2是段落编号 an8是书名只要书名一样,段落编号一样。
  9. * 两个就是关联段落
  10. *
  11. * 表名:cs6_para
  12. * 所以数据库结构是
  13. * book 书号 1-217
  14. * para 段落号
  15. * bookid
  16. * cspara 上述段落号
  17. * book_name 上述书名
  18. *
  19. * 输入 book para
  20. * 查询书名和段落号
  21. * 输入这个书名和段落号
  22. * 查询有多少段落有一样的书名和段落号
  23. * 有些book 里面有两本书。所以又加了一个bookid
  24. * 每个bookid代表一本真正的书。所以bookid 要比 book 多
  25. * bookid 是为了输出书名用的。不是为了查询相关段落
  26. *
  27. * 数据要求:
  28. * 制作时包含全部段落。做好后把没有相关段落的段落删掉??
  29. *
  30. */
  31. namespace App\Http\Controllers;
  32. use App\Models\RelatedParagraph;
  33. use Illuminate\Http\Request;
  34. use App\Http\Resources\RelatedParagraphResource;
  35. class RelatedParagraphController extends Controller
  36. {
  37. /**
  38. * Display a listing of the resource.
  39. *
  40. * @return \Illuminate\Http\Response
  41. */
  42. public function index(Request $request)
  43. {
  44. //
  45. $first = RelatedParagraph::where('book',$request->get('book'))
  46. ->where('para',$request->get('para'))
  47. ->where('cs_para','>',0)
  48. ->first();
  49. $result = RelatedParagraph::where('book_name',$first->book_name)
  50. ->where('cs_para',$first->cs_para)
  51. ->orderBy('book_id')
  52. ->orderBy('para')
  53. ->get();
  54. $books=[];
  55. foreach ($result as $value) {
  56. # 把段落整合成书。有几本书就有几条输出纪录
  57. if(!isset($books[$value->book_id])){
  58. $books[$value->book_id]['book'] = $value->book;
  59. $books[$value->book_id]['book_id'] = $value->book_id;
  60. $books[$value->book_id]['cs6_para'] = $value->cs_para;
  61. }
  62. $books[$value->book_id]['para'][]=$value->para;
  63. }
  64. return $this->ok(["rows"=>RelatedParagraphResource::collection($books),"count"=>count($books)]);
  65. }
  66. /**
  67. * Store a newly created resource in storage.
  68. *
  69. * @param \Illuminate\Http\Request $request
  70. * @return \Illuminate\Http\Response
  71. */
  72. public function store(Request $request)
  73. {
  74. //
  75. }
  76. /**
  77. * Display the specified resource.
  78. *
  79. * @param \App\Models\RelatedParagraph $relatedParagraph
  80. * @return \Illuminate\Http\Response
  81. */
  82. public function show(RelatedParagraph $relatedParagraph)
  83. {
  84. //
  85. }
  86. /**
  87. * Update the specified resource in storage.
  88. *
  89. * @param \Illuminate\Http\Request $request
  90. * @param \App\Models\RelatedParagraph $relatedParagraph
  91. * @return \Illuminate\Http\Response
  92. */
  93. public function update(Request $request, RelatedParagraph $relatedParagraph)
  94. {
  95. //
  96. }
  97. /**
  98. * Remove the specified resource from storage.
  99. *
  100. * @param \App\Models\RelatedParagraph $relatedParagraph
  101. * @return \Illuminate\Http\Response
  102. */
  103. public function destroy(RelatedParagraph $relatedParagraph)
  104. {
  105. //
  106. }
  107. }