2014-03-26 11:09:39 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: groups
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# name :string(255)
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# founder_id :integer
|
|
|
|
#
|
|
|
|
|
2014-03-23 00:22:25 +00:00
|
|
|
class Group < ActiveRecord::Base
|
|
|
|
include Extra
|
|
|
|
|
|
|
|
ADMINS = 1
|
|
|
|
REFEREES = 2
|
|
|
|
MOVIES = 3
|
|
|
|
DONORS = 4
|
|
|
|
MOVIEMAKERS = 5
|
2014-05-10 08:44:48 +00:00
|
|
|
CASTERS = 6
|
2014-03-23 00:22:25 +00:00
|
|
|
CHAMPIONS = 7
|
|
|
|
PREDICTORS = 8
|
|
|
|
STAFF = 10
|
2015-10-20 17:04:50 +00:00
|
|
|
GATHER_MODERATORS = 14
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
attr_protected :id, :updated_at, :created_at, :founder_id
|
|
|
|
validates_length_of :name, :maximum => 20
|
|
|
|
|
|
|
|
has_and_belongs_to_many :users
|
|
|
|
has_many :groupers
|
|
|
|
has_many :users, :through => :groupers
|
|
|
|
belongs_to :founder, :class_name => "User"
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
name
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_create? cuser
|
|
|
|
cuser and cuser.admin?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_update? cuser
|
|
|
|
cuser and cuser.admin?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_destroy? cuser
|
2014-04-27 00:34:38 +00:00
|
|
|
cuser and cuser.admin? and id != Group::ADMINS
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.staff
|
|
|
|
staff = []
|
2018-09-21 15:30:43 +00:00
|
|
|
|
|
|
|
(admins + casters + referees + extras).each do |g|
|
2014-03-23 00:22:25 +00:00
|
|
|
staff << g unless staff.include? g
|
|
|
|
end
|
|
|
|
staff
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.admins
|
|
|
|
admins = []
|
2018-09-21 15:30:43 +00:00
|
|
|
admin_group = where(id: ADMINS).first
|
|
|
|
return admins unless admin_group
|
|
|
|
|
|
|
|
(admin_group.groupers).each do |g|
|
2014-03-23 00:22:25 +00:00
|
|
|
admins << g unless admins.include? g
|
|
|
|
end
|
|
|
|
admins
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.referees
|
|
|
|
referees = []
|
2018-09-21 15:30:43 +00:00
|
|
|
referee_group = where(id: REFEREES).first
|
|
|
|
return referees unless referee_group
|
|
|
|
|
|
|
|
(referee_group.groupers).each do |g|
|
2014-03-23 00:22:25 +00:00
|
|
|
referees << g unless referees.include? g
|
|
|
|
end
|
|
|
|
referees
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.extras
|
|
|
|
extras = []
|
2018-09-21 15:30:43 +00:00
|
|
|
extra_group = where(id: PREDICTORS).first
|
|
|
|
staff_group = where(id: STAFF).first
|
|
|
|
|
|
|
|
extra_groupers = extra_group ? extra_group.groupers : []
|
|
|
|
staff_groupers = staff_group ? staff_group.groupers : []
|
|
|
|
|
|
|
|
(extra_groupers + staff_groupers).each do |g|
|
2014-03-23 00:22:25 +00:00
|
|
|
extras << g unless extras.include? g
|
|
|
|
end
|
|
|
|
extras
|
|
|
|
end
|
|
|
|
|
2014-05-10 08:44:48 +00:00
|
|
|
def self.casters
|
|
|
|
casters = []
|
2018-09-21 15:30:43 +00:00
|
|
|
caster_group = where(id:CASTERS).first
|
|
|
|
return casters unless caster_group
|
|
|
|
|
|
|
|
(caster_group.groupers).each do |g|
|
2014-05-10 08:44:48 +00:00
|
|
|
casters << g unless casters.include? g
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
2014-05-10 08:44:48 +00:00
|
|
|
casters
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
2017-06-21 07:39:30 +00:00
|
|
|
|
|
|
|
def self.gathermods
|
|
|
|
gathermods = []
|
2018-09-21 15:30:43 +00:00
|
|
|
gathermod_group = where(id:GATHER_MODERATORS).first
|
|
|
|
return gathermods unless gathermod_group
|
|
|
|
|
|
|
|
(gathermod_group.groupers).each do |g|
|
2017-06-21 07:39:30 +00:00
|
|
|
gathermods << g unless gathermods.include? g
|
|
|
|
end
|
|
|
|
gathermods
|
|
|
|
end
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|