- Made TrackedTimeEntries polymorphic to belong to both Lecture and WorkItems models - Added associated migrations for existing data - Added to administrate UI
48 lines
1.0 KiB
Ruby
48 lines
1.0 KiB
Ruby
class Lecture < ApplicationRecord
|
|
belongs_to :course
|
|
has_one :recording, dependent: :nullify
|
|
|
|
has_many :tracked_time_entries, dependent: :destroy, as: :subject
|
|
|
|
enum :kind, [
|
|
:lecture,
|
|
:problems_class,
|
|
], default: :lecture
|
|
|
|
def prepared?
|
|
tracked_time_entries.where(kind: [:preparation]).any?
|
|
end
|
|
|
|
def attended?
|
|
tracked_time_entries.where(kind: [:concurrent, :catchup]).any?
|
|
end
|
|
|
|
def reviewed?
|
|
tracked_time_entries.where(kind: [:review]).any?
|
|
end
|
|
|
|
def total_preparation_time
|
|
tracked_time_entries.preparation.sum(&:duration).seconds
|
|
end
|
|
|
|
def total_overall_time
|
|
tracked_time_entries.sum(&:duration).seconds
|
|
end
|
|
|
|
def total_attendance_time
|
|
tracked_time_entries.where(kind: [:concurrent, :catchup]).sum(&:duration).seconds
|
|
end
|
|
|
|
def total_review_time
|
|
tracked_time_entries.review.sum(&:duration).seconds
|
|
end
|
|
|
|
def week_number
|
|
((start_time.beginning_of_week - course.semester_start_date.to_time) / 1.week).floor + 1
|
|
end
|
|
|
|
def live_video_url
|
|
nil
|
|
end
|
|
end
|