2013-09-13 21:52:24 +08:00
|
|
|
class HomeworkAttach < ActiveRecord::Base
|
2014-04-09 09:25:24 +08:00
|
|
|
include Redmine::SafeAttributes
|
2014-05-19 17:44:36 +08:00
|
|
|
|
|
|
|
#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
|
2014-05-19 17:44:36 +08:00
|
|
|
has_many :homework_users, :dependent => :destroy
|
2014-06-11 15:28:13 +08:00
|
|
|
has_many :users, :through => :homework_users
|
2014-05-16 11:02:25 +08:00
|
|
|
seems_rateable :allow_update => true, :dimensions => :quality
|
2014-06-18 10:07:19 +08:00
|
|
|
belongs_to :project
|
2013-09-13 21:52:24 +08:00
|
|
|
|
2013-12-19 15:59:10 +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
|
|
|
|
2014-06-12 15:42:58 +08:00
|
|
|
def addjours user_id,message,status = 0,is_comprehensive_evaluation = 0,reply_id = 0
|
|
|
|
jfm = self.journals_for_messages.build(:user_id => user_id,:notes =>message,:status => status,:is_comprehensive_evaluation => is_comprehensive_evaluation,:reply_id => reply_id)
|
2014-05-17 11:15:27 +08:00
|
|
|
jfm.save
|
|
|
|
jfm
|
|
|
|
end
|
2014-05-17 13:49:27 +08:00
|
|
|
|
|
|
|
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-17 15:39:18 +08:00
|
|
|
|
2014-06-18 10:07:19 +08:00
|
|
|
def project_for_homework
|
2014-05-21 14:44:53 +08:00
|
|
|
work = HomeworkForCourse.find_by_bid_id(self.bid_id)
|
|
|
|
if work
|
|
|
|
work.project
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-17 15:39:18 +08:00
|
|
|
def add_jours options
|
|
|
|
jfm = self.journals_for_messages.build(options)
|
|
|
|
jfm.save
|
|
|
|
jfm
|
|
|
|
end
|
2013-09-13 21:52:24 +08:00
|
|
|
end
|