45 lines
1.1 KiB
Ruby
45 lines
1.1 KiB
Ruby
class HomeworkAttach < ActiveRecord::Base
|
|
include Redmine::SafeAttributes
|
|
|
|
#attr_accessible :name, :description, :state, :user_id, :bid_id
|
|
|
|
belongs_to :user
|
|
belongs_to :bid
|
|
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
|
has_many :homework_users, :dependent => :destroy
|
|
seems_rateable :allow_update => true, :dimensions => :quality
|
|
|
|
safe_attributes "bid_id",
|
|
"user_id"
|
|
acts_as_attachable
|
|
|
|
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
|
|
|
|
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
|
|
end
|