bigdir/app/models/homework_attach.rb

34 lines
820 B
Ruby
Raw Normal View History

2013-09-13 21:52:24 +08:00
class HomeworkAttach < ActiveRecord::Base
2014-04-09 09:25:24 +08:00
include Redmine::SafeAttributes
2013-09-13 21:52:24 +08:00
belongs_to :user
belongs_to :bid
2014-05-16 11:02:25 +08:00
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
seems_rateable :allow_update => true, :dimensions => :quality
2013-09-13 21:52:24 +08:00
safe_attributes "bid_id",
"user_id"
2013-09-13 21:52:24 +08:00
acts_as_attachable
2014-05-16 11:02:25 +08:00
def addjours user_id,message,status = 0
jfm = self.journals_for_messages.build(:user_id => user_id,:notes =>message,:status => status)
jfm.save
jfm
end
def score
stars_reates = self.rates(:quality)
percent = 0
stars_reates.each do |star_reates|
percent = percent + star_reates.stars
end
result = percent * 1.0 / stars_reates.count
result
end
def add_jours options
jfm = self.journals_for_messages.build(options)
jfm.save
jfm
end
2013-09-13 21:52:24 +08:00
end