You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pgfqe6ch8/app/models/competition.rb

44 lines
1.5 KiB

6 years ago
# 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
6 years ago
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
6 years ago
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
6 years ago
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
6 years ago
end