bigdir/app/models/homework_attach.rb

45 lines
1.1 KiB
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
#attr_accessible :name, :description, :state, :user_id, :bid_id
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
has_many :homework_users, :dependent => :destroy
2014-05-16 11:02:25 +08:00
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,is_comprehensive_evaluation = 0
jfm = self.journals_for_messages.build(:user_id => user_id,:notes =>message,:status => status,:is_comprehensive_evaluation => is_comprehensive_evaluation)
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
2014-05-21 14:44:53 +08:00
def project
work = HomeworkForCourse.find_by_bid_id(self.bid_id)
if work
work.project
end
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