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

36 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 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
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 + 268
end
end