hps_learning/app/models/hps_class.rb

25 lines
698 B
Ruby
Raw Normal View History

2017-07-04 16:58:50 +00:00
class HpsClass
include Mongoid::Document
include Mongoid::Timestamps
include OrbitTag::Taggable
include OrbitCategory::Categorizable
include Slug
mount_uploader :course_pic, ImageUploader
field :title, as: :slug_title, localize: true
has_many :hps_lectures, :autosave => true, :dependent => :destroy
def get_runtime
hours = 0
mins = 0
self.hps_lectures.pluck(:runtime_hours, :runtime_mins).each do |lec|
hours = hours + lec.first
mins = mins + lec.last
end
ht = mins / 60
mt = mins - (ht * 60)
hours = ht + hours
return hours.to_s + " " + I18n.t("hps_learning.hours") + " " + mt.to_s + " " + I18n.t("hps_learning.minutes")
end
end