socialforge/app/models/homework_attach.rb

28 lines
716 B
Ruby

class HomeworkAttach < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :user
belongs_to :bid
has_many :journals_for_messages, :as => :jour, :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
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
end