| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Http\Resources;
- use Illuminate\Http\Resources\Json\JsonResource;
- use App\Models\PaliSentence;
- use App\Models\PaliText;
- use App\Http\Api\UserApi;
- use App\Http\Api\ChannelApi;
- use App\Http\Controllers\CorpusController;
- use App\Http\Api\AuthApi;
- class SentSimResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @param \Illuminate\Http\Request $request
- * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
- */
- public function toArray($request)
- {
- //获取实际句子信息
- $sent = PaliSentence::find($this->sent2);
- $channelId = ChannelApi::getSysChannel('_System_Pali_VRI_');
- $sentOrg = [
- "id"=>$sent->id,
- "book"=> $sent->book,
- "para"=> $sent->paragraph,
- "wordStart"=> $sent->word_begin,
- "wordEnd"=> $sent->word_end,
- "editor"=> UserApi::getByUuid(config("app.admin.root_uuid")),
- "channel"=> ChannelApi::getById($channelId),
- "content"=>$sent->text,
- "html"=> "<span>{$sent->text}</span>",
- "role"=>"member",
- "created_at"=> $sent->created_at,
- "updated_at"=> $sent->updated_at,
- ];
- $user = AuthApi::current($request);
- if($user){
- $userUid = $user['user_uid'];
- }else{
- $userUid = null;
- }
- $resCount = CorpusController::sentCanReadCount($sent->book,$sent->paragraph,$sent->word_begin,$sent->word_end,$userUid);
- $result = [
- "id" => "{$sent->book}-{$sent->paragraph}-{$sent->word_begin}-{$sent->word_end}",
- "book"=> $sent->book,
- "para"=> $sent->paragraph,
- "wordStart"=> $sent->word_begin,
- "wordEnd"=> $sent->word_end,
- "origin" => [$sentOrg],
- "translation" => [],
- "layout" => "column",
- "tranNum" => $resCount['tranNum'],
- "nissayaNum" => $resCount['nissayaNum'],
- "commNum" => $resCount['commNum'],
- "originNum" => $resCount['originNum'],
- "simNum" => $resCount['simNum'],
- ];
- $result['path'] = json_decode(PaliText::where('book',$sent->book)
- ->where('paragraph',$sent->paragraph)
- ->value('path'));
- return $result;
- }
- }
|