ChannelProgressResource.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use App\Models\Channel;
  4. use Illuminate\Http\Request;
  5. /**
  6. * 一个 channel 在一批句子上的完成度:channel 本身 + `final` + 内容的最早 / 最近时间。
  7. *
  8. * `final` 与请求里的句子一一对应:`[原文字符数, 是否已译]`;这个 channel 在这批句子上一句都没译时为 null
  9. * (它出现在结果里是因为我能写它)。由 Service 挂上,本类不查库。
  10. *
  11. * @mixin Channel
  12. */
  13. class ChannelProgressResource extends ChannelResource
  14. {
  15. /**
  16. * @param Request $request
  17. * @return array{
  18. * id: string,
  19. * name: string,
  20. * summary: string|null,
  21. * type: string,
  22. * lang: string,
  23. * status: int,
  24. * is_system: bool,
  25. * source_type: string,
  26. * source_id: string|null,
  27. * owner: array{kind: string, id: string, nickName: string, realName: string, avatar: string|null},
  28. * abilities: array{read: bool, write: bool, update: bool, delete: bool},
  29. * final: array|null,
  30. * content_created_at: string|null,
  31. * content_updated_at: string|null,
  32. * created_at: string,
  33. * updated_at: string
  34. * }
  35. */
  36. public function toArray($request): array
  37. {
  38. return parent::toArray($request) + [
  39. 'final' => $this->getAttribute('final'),
  40. 'content_created_at' => $this->getAttribute('content_created_at'),
  41. 'content_updated_at' => $this->getAttribute('content_updated_at'),
  42. ];
  43. }
  44. }