socialforge/app/models/contestant_work.rb

34 lines
1.1 KiB
Ruby
Raw Normal View History

2016-12-22 10:01:37 +08:00
class ContestantWork < ActiveRecord::Base
2016-12-30 10:30:21 +08:00
include ContestantWorksHelper
2016-12-22 10:01:37 +08:00
belongs_to :work
belongs_to :user
belongs_to :project
2016-12-23 16:58:50 +08:00
attr_accessible :commit_time, :description, :is_delete, :name, :work_score, :work_status, :work_id, :user_id, :project_id
2016-12-22 10:01:37 +08:00
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
2016-12-30 10:30:21 +08:00
has_many :contestant_work_evaluation_distributions
before_save :set_work_score
2016-12-22 10:01:37 +08:00
2016-12-23 16:58:50 +08:00
scope :has_committed, lambda{where("work_status != 0 and work_status != 3")}
scope :no_copy, lambda{where("work_status != 3")}
2016-12-22 10:01:37 +08:00
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
2016-12-30 10:30:21 +08:00
def set_work_score
if self.id
set_final_score self.work,self
end
2016-12-30 10:30:21 +08:00
end
2016-12-22 10:01:37 +08:00
end