VideoTransformer.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Repositories\Transformers\Course;
  3. use App\Repositories\Enums\ModelStatusEnum;
  4. use Carbon\Carbon;
  5. use League\Fractal\TransformerAbstract;
  6. use App\Repositories\Models\Course\Video;
  7. /**
  8. * Class CourseVideoTransformer.
  9. *
  10. * @package namespace App\Repositories\Transformers;
  11. */
  12. class VideoTransformer extends TransformerAbstract
  13. {
  14. /**
  15. * Transform the CourseVideo entity.
  16. *
  17. * @param \App\Repositories\Models\Course\Video $model
  18. *
  19. * @return array
  20. */
  21. public function transform(Video $model)
  22. {
  23. return [
  24. 'id' => (int)$model->id,
  25. 'title' => $model->title,
  26. 'slug' => $model->slug,
  27. 'url' => $model->url,
  28. 'url_resource' => $model->url_resource ?? '',
  29. 'view_num' => $model->view_num,
  30. 'short_description' => $model->short_description,
  31. 'description' => $model->description,
  32. 'published_at' => $model->published_at,
  33. 'course_chapter_id' => $model->course_chapter_id,
  34. 'course_chapter_name' => $model->course_chapter ? $model->course_chapter->title : '',
  35. 'duration' => $model->duration,
  36. 'comment_status' => $model->comment_status,
  37. 'subtitle_zh_path' => $model->subtitle_zh_path,
  38. 'subtitle_zh_path_resource' => $model->subtitle_zh_path_resource ?? '',
  39. 'subtitle_en_path' => $model->subtitle_en_path,
  40. 'subtitle_en_path_resource' => $model->subtitle_en_path_resource ?? '',
  41. 'ban_drag' => $model->ban_drag,
  42. 'sort' => $model->sort,
  43. 'status' => $model->status,
  44. 'status_test' => ModelStatusEnum::getDescription($model->status),
  45. 'created_at' => $model->created_at->format(Carbon::DEFAULT_TO_STRING_FORMAT),
  46. 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
  47. ];
  48. }
  49. }