24 lines
952 B
Ruby
24 lines
952 B
Ruby
class ContestantWork < ActiveRecord::Base
|
|
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
|
|
|
|
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
|
|
end
|