# encoding: utf-8 class Competition < ActiveRecord::Base # status 0:下架, 1:上架 attr_accessible :end_time, :identifier, :name, :online_time, :start_time, :status, :visits, :competition_lists_count, :min_num, :max_num, :enroll_end_time, :sub_title, :published_at has_many :competition_modules, :dependent => :destroy has_many :competition_stages, :dependent => :destroy has_many :competition_stage_sections, :dependent => :destroy has_many :competition_lists, :dependent => :destroy has_many :competition_teams, :dependent => :destroy has_many :team_members, :dependent => :destroy has_many :chart_rules, :dependent => :destroy has_many :competition_scores, :dependent => :destroy has_many :competition_text_configs, :dependent => :destroy has_many :competition_staffs, dependent: :destroy acts_as_attachable after_create :create_competition_modules def create_competition_modules modules = ["首页", "报名", "通知公告", "排行榜", "资料下载"] modules.each_with_index do |name, index| self.competition_modules << CompetitionModule.new(:name => name, :position => index + 1) end end def to_param self.identifier.present? ? identifier : id end def member_count self.team_members.count == 0 ? 0 : self.team_members.count + 268 end def teacher_enroll_mutiple_limited competition_staffs.where(category: 'teacher').first.try(:mutiple_limited) end def member_enroll_mutiple_limited competition_staffs.where(category: 'student').first.try(:mutiple_limited) end end