CorpusController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Sentence;
  4. use App\Models\Channel;
  5. use App\Models\PaliText;
  6. use App\Models\WbwTemplate;
  7. use App\Models\WbwBlock;
  8. use App\Models\Wbw;
  9. use App\Models\Discussion;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\Cache;
  12. use App\Http\Api\MdRender;
  13. use App\Http\Api\SuggestionApi;
  14. use App\Http\Api\ChannelApi;
  15. use App\Http\Api\UserApi;
  16. use Illuminate\Support\Facades\Log;
  17. use Illuminate\Support\Arr;
  18. class CorpusController extends Controller
  19. {
  20. protected $result = [
  21. "uid"=> '',
  22. "title"=> '',
  23. "path"=>[],
  24. "sub_title"=> '',
  25. "summary"=> '',
  26. "content"=> '',
  27. "content_type"=> "html",
  28. "status"=>30,
  29. "lang"=> "",
  30. "created_at"=> "",
  31. "updated_at"=> "",
  32. ];
  33. protected $wbwChannels = [];
  34. protected $selectCol = ['book_id','paragraph','word_start',"word_end",'channel_uid','content','updated_at'];
  35. public function __construct()
  36. {
  37. }
  38. /**
  39. * Display a listing of the resource.
  40. *
  41. * @return \Illuminate\Http\Response
  42. */
  43. public function index()
  44. {
  45. //
  46. }
  47. /**
  48. * Store a newly created resource in storage.
  49. *
  50. * @param \Illuminate\Http\Request $request
  51. * @return \Illuminate\Http\Response
  52. */
  53. public function store(Request $request)
  54. {
  55. //
  56. }
  57. /**
  58. * Display the specified resource.
  59. *
  60. * @param \App\Models\Sentence $sentence
  61. * @return \Illuminate\Http\Response
  62. */
  63. public function show(Sentence $sentence)
  64. {
  65. //
  66. }
  67. public function getSentTpl($id,$channels,$mode='edit',$onlyProps=false){
  68. $sent = [];
  69. $sentId = \explode('-',$id);
  70. if($mode==='read'){
  71. $channelId = ChannelApi::getSysChannel('_System_Pali_VRI_');
  72. }else{
  73. $channelId = ChannelApi::getSysChannel('_System_Wbw_VRI_');
  74. }
  75. if($channelId !== false){
  76. array_push($channels,$channelId);
  77. }
  78. $record = Sentence::select($this->selectCol)
  79. ->where('book_id',$sentId[0])
  80. ->where('paragraph',$sentId[1])
  81. ->where('word_start',(int)$sentId[2])
  82. ->where('word_end',(int)$sentId[3])
  83. ->whereIn('channel_uid',$channels)
  84. ->get();
  85. Log::info("sent count:".count($record));
  86. $channelIndex = $this->getChannelIndex($channels);
  87. //获取wbw channel
  88. //目前默认的 wbw channel 是第一个translation channel
  89. foreach ($channels as $channel) {
  90. # code...
  91. if($channelIndex[$channel]->type==='translation'){
  92. $this->wbwChannels[] = $channel;
  93. break;
  94. }
  95. }
  96. return $this->makeContent($record,$mode,$channelIndex,[],$onlyProps);
  97. }
  98. /**
  99. * Display the specified resource.
  100. *
  101. * @param string $id
  102. * @return \Illuminate\Http\Response
  103. */
  104. public function showSent($id)
  105. {
  106. //
  107. $param = \explode('_',$id);
  108. if(count($param)>1){
  109. $channels = array_slice($param,1);
  110. }else{
  111. $channels = [];
  112. }
  113. $this->result['content'] = getSentTpl($param[0],$channels);
  114. return $this->ok($this->result);
  115. }
  116. public function showSentences($type,$id,$mode='read'){
  117. $param = \explode('_',$id);
  118. $sentId = \explode('-',$param[0]);
  119. $channels = [];
  120. #获取channel类型
  121. $sentChannel = Sentence::select('channel_uid')
  122. ->where('book_id',$sentId[0])
  123. ->where('paragraph',$sentId[1])
  124. ->where('word_start',$sentId[2])
  125. ->where('word_end',$sentId[3])
  126. ->get();
  127. foreach ($sentChannel as $key => $value) {
  128. # code...
  129. $channels[] = $value->channel_uid;
  130. }
  131. $channelInfo = Channel::whereIn("uid",$channels)->select(['uid','type','name'])->get();
  132. $indexChannel = [];
  133. $channels = [];
  134. foreach ($channelInfo as $key => $value) {
  135. # code...
  136. if($value->type === $type){
  137. $indexChannel[$value->uid] = $value;
  138. $channels[] = $value->uid;
  139. }
  140. }
  141. //获取句子数据
  142. $record = Sentence::select($this->selectCol)
  143. ->where('book_id',$sentId[0])
  144. ->where('paragraph',$sentId[1])
  145. ->where('word_start',$sentId[2])
  146. ->where('word_end',$sentId[3])
  147. ->whereIn('channel_uid',$channels)
  148. ->orderBy('paragraph')
  149. ->orderBy('word_start')
  150. ->get();
  151. if(count($record) ===0){
  152. return $this->error("no data");
  153. }
  154. $this->result['content'] = $this->makeContent($record,$mode,$indexChannel);
  155. return $this->ok($this->result);
  156. }
  157. public function showChapter($id,$mode='read')
  158. {
  159. //
  160. $param = \explode('_',$id);
  161. $sentId = \explode('-',$param[0]);
  162. $channels = [];
  163. if(count($param)>1){
  164. $channels = array_slice($param,1);
  165. }
  166. if($mode === 'read'){
  167. //阅读模式加载md格式原文
  168. $channelId = ChannelApi::getSysChannel('_System_Pali_VRI_');
  169. }else{
  170. //翻译模式加载json格式原文
  171. $channelId = ChannelApi::getSysChannel('_System_Wbw_VRI_');
  172. }
  173. if($channelId !== false){
  174. $channels[] = $channelId;
  175. }
  176. $chapter = PaliText::where('book',$sentId[0])->where('paragraph',$sentId[1])->first();
  177. if(!$chapter){
  178. return $this->error("no data");
  179. }
  180. if(empty($chapter->toc)){
  181. $this->result['title'] = "unknown";
  182. }else{
  183. $this->result['title'] = $chapter->toc;
  184. $this->result['sub_title'] = $chapter->toc;
  185. $this->result['path'] = json_decode($chapter->path);
  186. }
  187. $paraFrom = $sentId[1];
  188. $paraTo = $sentId[1]+$chapter->chapter_len-1;
  189. //获取标题
  190. $heading = PaliText::select(["book","paragraph","level"])
  191. ->where('book',$sentId[0])
  192. ->whereBetween('paragraph',[$paraFrom,$paraTo])
  193. ->where('level','<',8)
  194. ->get();
  195. //将标题段落转成索引数组 以便输出标题层级
  196. $indexedHeading = [];
  197. foreach ($heading as $key => $value) {
  198. # code...
  199. $indexedHeading["{$value->book}-{$value->paragraph}"] = $value->level;
  200. }
  201. #获取channel索引表
  202. $tranChannels = [];
  203. $channelInfo = Channel::whereIn("uid",$channels)->select(['uid','type','name'])->get();
  204. $indexChannel = [];
  205. foreach ($channelInfo as $key => $value) {
  206. # code...
  207. $indexChannel[$value->uid] = $value;
  208. if($value->type==="translation" ){
  209. $tranChannels[] = $value->uid;
  210. }
  211. }
  212. //获取wbw channel
  213. //目前默认的 wbw channel 是第一个translation channel
  214. foreach ($channels as $key => $value) {
  215. # code...
  216. if($indexChannel[$value]->type==='translation'){
  217. $this->wbwChannels[] = $value;
  218. break;
  219. }
  220. }
  221. $title = Sentence::select($this->selectCol)
  222. ->where('book_id',$sentId[0])
  223. ->where('paragraph',$sentId[1])
  224. ->whereIn('channel_uid',$tranChannels)
  225. ->first();
  226. if($title){
  227. $this->result['title'] = MdRender::render($title->content,$title->channel_uid);
  228. }
  229. //获取句子数据
  230. $record = Sentence::select($this->selectCol)
  231. ->where('book_id',$sentId[0])
  232. ->whereBetween('paragraph',[$paraFrom,$paraTo])
  233. ->whereIn('channel_uid',$channels)
  234. ->orderBy('paragraph')
  235. ->orderBy('word_start')
  236. ->get();
  237. if(count($record) ===0){
  238. return $this->error("no data");
  239. }
  240. $this->result['content'] = $this->makeContent($record,$mode,$indexChannel,$indexedHeading);
  241. return $this->ok($this->result);
  242. }
  243. private function getChannelIndex($channels){
  244. #获取channel索引表
  245. $channelInfo = Channel::whereIn("uid",$channels)->select(['uid','type','name'])->get();
  246. $indexChannel = [];
  247. foreach ($channelInfo as $key => $value) {
  248. # code...
  249. $indexChannel[$value->uid] = $value;
  250. }
  251. return $indexChannel;
  252. }
  253. /**
  254. * 根据句子库数据生成文章内容
  255. * $record 句子数据
  256. * $mode read | edit | wbw
  257. * $indexChannel channel索引
  258. * $indexedHeading 标题索引 用于给段落加标题标签 <h1> ect.
  259. */
  260. private function makeContent($record,$mode,$indexChannel,$indexedHeading=[],$onlyProps=false){
  261. $content = [];
  262. $lastSent = "0-0";
  263. $sentCount = 0;
  264. $sent = [];
  265. $sent["origin"] = [];
  266. $sent["translation"] = [];
  267. //获取句子编号列表
  268. $sentList = [];
  269. foreach ($record as $key => $value) {
  270. $currSentId = "{$value->book_id}-{$value->paragraph}-{$value->word_start}-{$value->word_end}";
  271. $sentList[$currSentId]=[$value->book_id ,$value->paragraph,$value->word_start,$value->word_end];
  272. $value['sid'] = "{$currSentId}_{$value->channel_uid}";
  273. }
  274. //遍历列表查找每个句子的所有channel的数据,并填充
  275. foreach ($sentList as $currSentId => $arrSentId) {
  276. # code...
  277. $sent = $this->newSent($arrSentId[0],$arrSentId[1],$arrSentId[2],$arrSentId[3]);
  278. $sent["origin"] = [];
  279. $sent["translation"] = [];
  280. foreach ($indexChannel as $channelId => $info) {
  281. # code...
  282. $sid = "{$currSentId}_{$channelId}";
  283. $newSent = [
  284. "content"=>"",
  285. "html"=> "",
  286. "book"=> $arrSentId[0],
  287. "para"=> $arrSentId[1],
  288. "wordStart"=> $arrSentId[2],
  289. "wordEnd"=> $arrSentId[3],
  290. "channel"=> [
  291. "name"=>$info->name,
  292. "type"=>$info->type,
  293. "id"=> $info->uid,
  294. ],
  295. "updateAt"=> "",
  296. "suggestionCount" => SuggestionApi::getCountBySent($arrSentId[0],$arrSentId[1],$arrSentId[2],$arrSentId[3],$channelId),
  297. ];
  298. $row = Arr::first($record,function($value,$key) use($sid){
  299. return $value['sid']===$sid;
  300. });
  301. if($row){
  302. $newSent['content'] = $row->content;
  303. $newSent['html'] = "";
  304. $newSent["editor"]=UserApi::getById($row->editor_uid);
  305. $newSent['updateAt'] = $row->updated_at;
  306. switch ($info->type) {
  307. case 'wbw':
  308. case 'original':
  309. //
  310. // 在编辑模式下。
  311. // 如果是原文,查看是否有逐词解析数据,
  312. // 有的话优先显示。
  313. // 阅读模式直接显示html原文
  314. // 传过来的数据一定有一个原文channel
  315. //
  316. if($mode !== "read"){
  317. $newSent['channel']['type'] = "wbw";
  318. if(isset($this->wbwChannels[0])){
  319. //存在一个translation channel
  320. //尝试查找逐词解析数据。找到,替换现有数据
  321. $wbwData = $this->getWbw($arrSentId[0],$arrSentId[1],$arrSentId[2],$arrSentId[3],$channelId);
  322. if($wbwData){
  323. $newSent['content'] = $wbwData;
  324. $newSent['html'] = "";
  325. }
  326. }
  327. }else{
  328. $newSent['html'] = $row->content;
  329. $newSent['content'] = "";
  330. }
  331. break;
  332. default:
  333. //译文需要markdown渲染
  334. $newSent['html'] = Cache::remember("/sent/{$channelId}/{$currSentId}",10,
  335. function() use($row){
  336. return MdRender::render($row->content,$row->channel_uid);
  337. });
  338. break;
  339. }
  340. }
  341. switch ($info->type) {
  342. case 'wbw':
  343. case 'original':
  344. array_push($sent["origin"],$newSent);
  345. break;
  346. default:
  347. array_push($sent["translation"],$newSent);
  348. break;
  349. }
  350. }
  351. if($onlyProps){
  352. return $sent;
  353. }
  354. $content = $this->pushSent($content,$sent,0,$mode);
  355. }
  356. /*
  357. foreach ($record as $key => $value) {
  358. # 遍历结果生成html文件
  359. $currSentId = $value->book_id.'-'.$value->paragraph.'-'.$value->word_start.'-'.$value->word_end;
  360. if($currSentId !== $lastSent){
  361. if($sentCount > 0){
  362. //保存上一个句子
  363. //增加标题的html标记
  364. $level = 0;
  365. if(isset($indexedHeading["{$value->book_id}-{$value->paragraph}"])){
  366. $level = $indexedHeading["{$value->book_id}-{$value->paragraph}"];
  367. }
  368. $content = $this->pushSent($content,$sent,$level,$mode);
  369. }
  370. //新建句子
  371. $sent = $this->newSent($value->book_id,$value->paragraph,$value->word_start,$value->word_end);
  372. $lastSent = $currSentId;
  373. }
  374. $sentContent=$value->content;
  375. $channelType = $indexChannel[$value->channel_uid]->type;
  376. if($indexChannel[$value->channel_uid]->type==="original" && $mode !== 'read'){
  377. //非阅读模式下。原文使用逐词解析数据。优先加载第一个translation channel 如果没有。加载默认逐词解析。
  378. $channelType = 'wbw';
  379. $html = "";
  380. if(count($this->wbwChannels)>0){
  381. //获取逐词解析数据
  382. $wbwBlock = WbwBlock::where('channel_uid',$this->wbwChannels[0])
  383. ->where('book_id',$value->book_id)
  384. ->where('paragraph',$value->paragraph)
  385. ->select('uid')
  386. ->first();
  387. if($wbwBlock){
  388. //找到逐词解析数据
  389. $wbwData = Wbw::where('block_uid',$wbwBlock->uid)
  390. ->whereBetween('wid',[$value->word_start,$value->word_end])
  391. ->select(['data','uid'])
  392. ->orderBy('wid')
  393. ->get();
  394. $wbwContent = [];
  395. foreach ($wbwData as $wbwrow) {
  396. $wbw = str_replace("&nbsp;",' ',$wbwrow->data);
  397. $wbw = str_replace("<br>",' ',$wbw);
  398. $xmlString = "<root>" . $wbw . "</root>";
  399. try{
  400. $xmlWord = simplexml_load_string($xmlString);
  401. }catch(Exception $e){
  402. continue;
  403. }
  404. $wordsList = $xmlWord->xpath('//word');
  405. foreach ($wordsList as $word) {
  406. $case = \str_replace(['#','.'],['$',''],$word->case->__toString());
  407. $case = \str_replace('$$','$',$case);
  408. $case = trim($case);
  409. $case = trim($case,"$");
  410. $wbwContent[] = [
  411. 'uid'=>$wbwrow->uid,
  412. 'word'=>['value'=>$word->pali->__toString(),'status'=>0],
  413. 'real'=> ['value'=>$word->real->__toString(),'status'=>0],
  414. 'meaning'=> ['value'=>\explode('$',$word->mean->__toString()) ,'status'=>0],
  415. 'type'=> ['value'=>$word->type->__toString(),'status'=>0],
  416. 'grammar'=> ['value'=>$word->gramma->__toString(),'status'=>0],
  417. 'case'=> ['value'=>\explode('$',$case),'status'=>0],
  418. 'parent'=> ['value'=>$word->parent->__toString(),'status'=>0],
  419. 'style'=> ['value'=>$word->style->__toString(),'status'=>0],
  420. 'factors'=> ['value'=>$word->org->__toString(),'status'=>0],
  421. 'factorMeaning'=> ['value'=>$word->om->__toString(),'status'=>0],
  422. 'confidence'=> 0.5,
  423. 'hasComment'=>Discussion::where('res_id',$wbwrow->uid)->exists(),
  424. ];
  425. }
  426. }
  427. $sentContent = \json_encode($wbwContent);
  428. }
  429. }
  430. }else{
  431. if($indexChannel[$value->channel_uid]->type==="original"){
  432. //原文直接使用
  433. $html = Cache::remember("/sent/{$value->channel_uid}/{$currSentId}",10,
  434. function() use($value){
  435. return $value->content;
  436. });
  437. }else{
  438. //译文需要markdown渲染
  439. $html = Cache::remember("/sent/{$value->channel_uid}/{$currSentId}",10,
  440. function() use($value){
  441. return MdRender::render($value->content,$value->channel_uid);
  442. });
  443. }
  444. }
  445. $newSent = [
  446. "content"=>$sentContent,
  447. "html"=> $html,
  448. "book"=> $value->book_id,
  449. "para"=> $value->paragraph,
  450. "wordStart"=> $value->word_start,
  451. "wordEnd"=> $value->word_end,
  452. "editor"=> [
  453. 'id'=>$value->editor_uid,
  454. 'nickName'=>'nickname',
  455. 'realName'=>'realName',
  456. 'avatar'=>'',
  457. ],
  458. "channel"=> [
  459. "name"=>$indexChannel[$value->channel_uid]->name,
  460. "type"=>$channelType,
  461. "id"=> $value->channel_uid,
  462. ],
  463. "updateAt"=> $value->updated_at,
  464. "suggestionCount" => SuggestionApi::getCountBySent($value->book_id,$value->paragraph,$value->word_start,$value->word_end,$value->channel_uid),
  465. ];
  466. switch ($indexChannel[$value->channel_uid]->type) {
  467. case 'original';
  468. case 'wbw';
  469. array_push($sent["origin"],$newSent);
  470. break;
  471. default:
  472. array_push($sent["translation"],$newSent);
  473. break;
  474. }
  475. $sentCount++;
  476. }
  477. if($onlyProps){
  478. return $sent;
  479. }
  480. $content = $this->pushSent($content,$sent,0,$mode);
  481. */
  482. $output = \implode("",$content);
  483. return "<div>{$output}</div>";
  484. }
  485. private function getWbw($book,$para,$start,$end,$channel){
  486. /**
  487. * 非阅读模式下。原文使用逐词解析数据。
  488. * 优先加载第一个translation channel 如果没有。加载默认逐词解析。
  489. */
  490. //获取逐词解析数据
  491. $wbwBlock = WbwBlock::where('channel_uid',$channel)
  492. ->where('book_id',$book)
  493. ->where('paragraph',$para)
  494. ->select('uid')
  495. ->first();
  496. if(!$wbwBlock){
  497. return false;
  498. }
  499. //找到逐词解析数据
  500. $wbwData = Wbw::where('block_uid',$wbwBlock->uid)
  501. ->whereBetween('wid',[$start,$end])
  502. ->select(['data','uid'])
  503. ->orderBy('wid')
  504. ->get();
  505. $wbwContent = [];
  506. foreach ($wbwData as $wbwrow) {
  507. $wbw = str_replace("&nbsp;",' ',$wbwrow->data);
  508. $wbw = str_replace("<br>",' ',$wbw);
  509. $xmlString = "<root>" . $wbw . "</root>";
  510. try{
  511. $xmlWord = simplexml_load_string($xmlString);
  512. }catch(Exception $e){
  513. continue;
  514. }
  515. $wordsList = $xmlWord->xpath('//word');
  516. foreach ($wordsList as $word) {
  517. $case = \str_replace(['#','.'],['$',''],$word->case->__toString());
  518. $case = \str_replace('$$','$',$case);
  519. $case = trim($case);
  520. $case = trim($case,"$");
  521. $wbwContent[] = [
  522. 'uid'=>$wbwrow->uid,
  523. 'word'=>['value'=>$word->pali->__toString(),'status'=>0],
  524. 'real'=> ['value'=>$word->real->__toString(),'status'=>0],
  525. 'meaning'=> ['value'=>\explode('$',$word->mean->__toString()) ,'status'=>0],
  526. 'type'=> ['value'=>$word->type->__toString(),'status'=>0],
  527. 'grammar'=> ['value'=>$word->gramma->__toString(),'status'=>0],
  528. 'case'=> ['value'=>\explode('$',$case),'status'=>0],
  529. 'parent'=> ['value'=>$word->parent->__toString(),'status'=>0],
  530. 'style'=> ['value'=>$word->style->__toString(),'status'=>0],
  531. 'factors'=> ['value'=>$word->org->__toString(),'status'=>0],
  532. 'factorMeaning'=> ['value'=>$word->om->__toString(),'status'=>0],
  533. 'confidence'=> 0.5,
  534. 'hasComment'=>Discussion::where('res_id',$wbwrow->uid)->exists(),
  535. ];
  536. }
  537. }
  538. return \json_encode($wbwContent,JSON_UNESCAPED_UNICODE);
  539. }
  540. /**
  541. * 将句子放进结果列表
  542. */
  543. private function pushSent($result,$sent,$level=0,$mode='read'){
  544. $sentProps = base64_encode(\json_encode($sent)) ;
  545. if($mode === 'read'){
  546. $sentWidget = "<MdTpl tpl='sentread' props='{$sentProps}' />";
  547. }else{
  548. $sentWidget = "<MdTpl tpl='sentedit' props='{$sentProps}' />";
  549. }
  550. //增加标题的html标记
  551. if($level>0){
  552. $sentWidget = "<h{$level}>".$sentWidget."</h{$level}>";
  553. }
  554. array_push($result,$sentWidget);
  555. return $result;
  556. }
  557. private function newSent($book,$para,$word_start,$word_end){
  558. $sent = [
  559. "id"=>"{$book}-{$para}-{$word_start}-{$word_end}",
  560. "origin"=>[],
  561. "translation"=>[],
  562. ];
  563. #生成channel 数量列表
  564. $sentId = "{$book}-{$para}-{$word_start}-{$word_end}";
  565. $channelCount = Cache::remember("/sent1/{$sentId}/channels/count",
  566. 60,
  567. function() use($book,$para,$word_start,$word_end){
  568. $channels = Sentence::where('book_id',$book)
  569. ->where('paragraph',$para)
  570. ->where('word_start',$word_start)
  571. ->where('word_end',$word_end)
  572. ->select('channel_uid')
  573. ->groupBy('channel_uid')
  574. ->get();
  575. $channelList = [];
  576. foreach ($channels as $key => $value) {
  577. # code...
  578. $channelList[] = $value->channel_uid;
  579. }
  580. $channelInfo = Channel::whereIn("uid",$channelList)->select('type')->get();
  581. $output["tranNum"]=0;
  582. $output["nissayaNum"]=0;
  583. $output["commNum"]=0;
  584. $output["originNum"]=0;
  585. foreach ($channelInfo as $key => $value) {
  586. # code...
  587. switch($value->type){
  588. case "translation":
  589. $output["tranNum"]++;
  590. break;
  591. case "nissaya":
  592. $output["nissayaNum"]++;
  593. break;
  594. case "commentary":
  595. $output["commNum"]++;
  596. break;
  597. case "original":
  598. $output["originNum"]++;
  599. break;
  600. }
  601. }
  602. return $output;
  603. });
  604. $sent["tranNum"] = $channelCount['tranNum'];
  605. $sent["nissayaNum"] = $channelCount['nissayaNum'];
  606. $sent["commNum"] = $channelCount['commNum'];
  607. $sent["originNum"] = $channelCount['originNum'];
  608. return $sent;
  609. }
  610. private function markdownRender($input){
  611. }
  612. /**
  613. * Update the specified resource in storage.
  614. *
  615. * @param \Illuminate\Http\Request $request
  616. * @param \App\Models\Sentence $sentence
  617. * @return \Illuminate\Http\Response
  618. */
  619. public function update(Request $request, Sentence $sentence)
  620. {
  621. //
  622. }
  623. /**
  624. * Remove the specified resource from storage.
  625. *
  626. * @param \App\Models\Sentence $sentence
  627. * @return \Illuminate\Http\Response
  628. */
  629. public function destroy(Sentence $sentence)
  630. {
  631. //
  632. }
  633. }