2014-03-26 11:09:39 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: weeks
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# name :string(255)
|
|
|
|
# start_date :date
|
2020-03-18 03:38:17 +00:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2014-03-26 11:09:39 +00:00
|
|
|
# contest_id :integer
|
|
|
|
# map1_id :integer
|
|
|
|
# map2_id :integer
|
2020-03-18 03:38:17 +00:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_weeks_on_contest_id (contest_id)
|
|
|
|
# index_weeks_on_map1_id (map1_id)
|
|
|
|
# index_weeks_on_map2_id (map2_id)
|
2014-03-26 11:09:39 +00:00
|
|
|
#
|
|
|
|
|
2014-03-23 00:22:25 +00:00
|
|
|
class Week < ActiveRecord::Base
|
|
|
|
include Extra
|
|
|
|
|
2020-03-16 23:57:47 +00:00
|
|
|
#attr_protected :id, :updated_at, :created_at
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
validates_presence_of :contest, :map1, :map2
|
|
|
|
validates_length_of :name, :in => 1..30
|
|
|
|
|
2020-03-16 20:57:41 +00:00
|
|
|
scope :ordered, -> { order("start_date ASC") }
|
2014-03-23 00:22:25 +00:00
|
|
|
|
2020-03-26 02:26:30 +00:00
|
|
|
belongs_to :contest, :optional => true
|
|
|
|
belongs_to :map1, :class_name => "Map", :optional => true
|
|
|
|
belongs_to :map2, :class_name => "Map", :optional => true
|
2014-03-23 00:22:25 +00:00
|
|
|
has_many :matches
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
self.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_create? cuser
|
|
|
|
cuser and cuser.admin?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_update? cuser
|
|
|
|
cuser and cuser.admin?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_destroy? cuser
|
|
|
|
cuser and cuser.admin?
|
|
|
|
end
|
2020-03-18 03:38:17 +00:00
|
|
|
|
|
|
|
def self.params(params, cuser)
|
|
|
|
params.require(:week).permit(:name, :start_date, :contest_id, :map1_id, :map2_id)
|
|
|
|
end
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|