Video.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Repositories\Models\Course;
  3. use App\Repositories\Models\Model;
  4. use App\Repositories\Models\Base\Resource;
  5. //use App\Repositories\Models\UserVideoWatchRecord;
  6. use Prettus\Repository\Contracts\Transformable;
  7. use Prettus\Repository\Traits\TransformableTrait;
  8. /**
  9. * Class CourseVideo.
  10. *
  11. * @package namespace App\Repositories\Models;
  12. */
  13. class Video extends Model implements Transformable
  14. {
  15. use TransformableTrait;
  16. protected $table = 'course_videos';
  17. /**
  18. * The attributes that are mass assignable.
  19. *
  20. * @var array
  21. */
  22. // protected $fillable = [];
  23. protected $guarded = [];
  24. protected static function booted()
  25. {
  26. self::language();
  27. }
  28. public function getDurationTextAttribute()
  29. {
  30. return sec2time($this->attributes['duration']);
  31. }
  32. public function comments()
  33. {
  34. return $this->hasMany(Comment::class, 'course_video_id');
  35. }
  36. public function attaches()
  37. {
  38. return $this->hasMany(Attach::class, 'course_video_id');
  39. }
  40. public function course_chapter()
  41. {
  42. return $this->belongsTo(Chapter::class);
  43. }
  44. public function course()
  45. {
  46. return $this->belongsTo(Course::class);
  47. }
  48. public function getProgressAttribute()
  49. {
  50. return 0;
  51. // return UserVideoWatchRecord::query()->where('video_id', $this->attributes['id'])->where('user_id', login_user_id())->value('progress') ?? 0;
  52. }
  53. public function url_resource()
  54. {
  55. return $this->belongsTo(Resource::class, 'url', 'id')->select(['path', 'id', 'url']);
  56. }
  57. public function subtitle_zh_path_resource()
  58. {
  59. return $this->belongsTo(Resource::class, 'subtitle_zh_path', 'id')->select(['path', 'id', 'url']);
  60. }
  61. public function subtitle_en_path_resource()
  62. {
  63. return $this->belongsTo(Resource::class, 'subtitle_en_path', 'id')->select(['path', 'id', 'url']);
  64. }
  65. }