You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
913 B
41 lines
913 B
class Video < ApplicationRecord
|
|
include AASM
|
|
|
|
belongs_to :user
|
|
|
|
has_many :video_applies, dependent: :destroy
|
|
has_many :course_videos, dependent: :destroy
|
|
has_one :processing_video_apply, -> { where(status: :pending) }, class_name: 'VideoApply'
|
|
|
|
aasm(:status) do
|
|
state :pending, initial: true
|
|
state :processing
|
|
state :refused
|
|
state :published
|
|
|
|
event :apply_publish do
|
|
transitions from: :pending, to: :processing
|
|
end
|
|
|
|
event :refuse do
|
|
transitions from: :processing, to: :refused
|
|
end
|
|
|
|
event :publish do
|
|
transitions from: :processing, to: :published, guard: :vod_uploaded?
|
|
end
|
|
end
|
|
|
|
aasm(:vod_status, namespace: :vod) do
|
|
state :uploading, initial: true
|
|
state :uploaded
|
|
|
|
event :upload_success do
|
|
transitions from: :uploading, to: :uploaded
|
|
end
|
|
end
|
|
|
|
def video_play_duration
|
|
(play_duration / (60*60.0)).ceil
|
|
end
|
|
end |