socialforge/app/models/contestant_work.rb

34 lines
1.1 KiB
Ruby

class ContestantWork < ActiveRecord::Base
include ContestantWorksHelper
belongs_to :work
belongs_to :user
belongs_to :project
attr_accessible :commit_time, :description, :is_delete, :name, :work_score, :work_status, :work_id, :user_id, :project_id
has_many :contestant_work_projects, :dependent => :destroy
has_many :contestant_work_scores, :dependent => :destroy
has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy
has_many :attachments, :dependent => :destroy
has_many :contestant_work_evaluation_distributions
before_save :set_work_score
scope :has_committed, lambda{where("work_status != 0 and work_status != 3")}
scope :no_copy, lambda{where("work_status != 3")}
after_create :act_as_message
acts_as_attachable
def act_as_message
if self.work_status != 0 && self.created_at > self.work.end_time + 1
self.contest_messages << ContestMessage.new(:user_id => self.user_id, :contest_id => self.work.contest_id, :viewed => false, :status => false)
end
end
def set_work_score
if self.id
set_final_score self.work,self
end
end
end