ExportWbwController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Wbw;
  4. use App\Models\WbwBlock;
  5. use Illuminate\Http\Request;
  6. class ExportWbwController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return \Illuminate\Http\Response
  12. */
  13. public function index(Request $request)
  14. {
  15. //
  16. $sent = explode("\n",$request->get("sent"));
  17. $output = [];
  18. foreach ($sent as $key => $value) {
  19. # code...
  20. $sent = [];
  21. $value = trim($value);
  22. $sentId = explode("-",$value);
  23. //先查wbw block 拿到block id
  24. $block = WbwBlock::where('book_id',$sentId[0])
  25. ->where('paragraph',$sentId[1])
  26. ->select('uid')
  27. ->where('channel_uid',$request->get("channel"))->first();
  28. if(!$block){
  29. continue;
  30. }
  31. $wbwdata = Wbw::where('book_id',$sentId[0])
  32. ->where('paragraph',$sentId[1])
  33. ->where('wid','>=',$sentId[2])
  34. ->where('wid','<=',$sentId[3])
  35. ->where('block_uid',$block->uid)
  36. ->get();
  37. $sent['sid']=$value;
  38. $sent['data']=[];
  39. foreach ($wbwdata as $wbw) {
  40. # code...
  41. $data = str_replace("&nbsp;",' ',$wbw->data);
  42. $data = str_replace("<br>",' ',$data);
  43. $xmlString = "<root>" . $data . "</root>";
  44. try{
  45. $xmlWord = simplexml_load_string($xmlString);
  46. }catch(Exception $e){
  47. continue;
  48. }
  49. $wordsList = $xmlWord->xpath('//word');
  50. foreach ($wordsList as $word) {
  51. $type = $word->type->__toString();
  52. $style = $word->style->__toString();
  53. if($type !== '.ctl.' && $style !== 'note'){
  54. $sent['data'][]=[
  55. 'pali'=>$word->real->__toString(),
  56. 'mean' => $word->mean->__toString(),
  57. 'type' => ltrim($type,'.'),
  58. 'grammar' => ltrim(str_replace('$.',',',$word->gramma->__toString()),'.') ,
  59. 'parent' => $word->parent->__toString(),
  60. 'factors' => $word->org->__toString(),
  61. 'factormeaning' => $word->om->__toString()
  62. ];
  63. }
  64. }
  65. }
  66. $output[]=$sent;
  67. }
  68. return view('export_wbw',['sentences' => $output] );
  69. }
  70. /**
  71. * Store a newly created resource in storage.
  72. *
  73. * @param \Illuminate\Http\Request $request
  74. * @return \Illuminate\Http\Response
  75. */
  76. public function store(Request $request)
  77. {
  78. //
  79. }
  80. /**
  81. * Display the specified resource.
  82. *
  83. * @param \App\Models\Wbw $wbw
  84. * @return \Illuminate\Http\Response
  85. */
  86. public function show(Wbw $wbw)
  87. {
  88. //
  89. }
  90. /**
  91. * Update the specified resource in storage.
  92. *
  93. * @param \Illuminate\Http\Request $request
  94. * @param \App\Models\Wbw $wbw
  95. * @return \Illuminate\Http\Response
  96. */
  97. public function update(Request $request, Wbw $wbw)
  98. {
  99. //
  100. }
  101. /**
  102. * Remove the specified resource from storage.
  103. *
  104. * @param \App\Models\Wbw $wbw
  105. * @return \Illuminate\Http\Response
  106. */
  107. public function destroy(Wbw $wbw)
  108. {
  109. //
  110. }
  111. }