lecture-attendance-manager/app/models/lecture.rb
Joshua Coles 6a2f053bb6 Added WorkItems as a new subject for TrackedTimeEntries.
- Made TrackedTimeEntries polymorphic to belong to both Lecture and WorkItems models
- Added associated migrations for existing data
- Added to administrate UI
2023-10-07 15:53:31 +01:00

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