mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 04:51:14 +00:00
More progress on Rails 4.1 update
Just fix scopes mostly. Add binstubs.
This commit is contained in:
parent
768d3faa1b
commit
ce9797aed8
20 changed files with 189 additions and 213 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -20,6 +20,7 @@
|
||||||
/public/files/*
|
/public/files/*
|
||||||
/public/local
|
/public/local
|
||||||
/public/uploads
|
/public/uploads
|
||||||
|
/public/assets/
|
||||||
|
|
||||||
# RubyMine
|
# RubyMine
|
||||||
/.idea
|
/.idea
|
||||||
|
@ -43,4 +44,4 @@ rerun.txt
|
||||||
pickle-email-*.html
|
pickle-email-*.html
|
||||||
|
|
||||||
# Direnv
|
# Direnv
|
||||||
.envrc
|
.envrc
|
||||||
|
|
|
@ -10,9 +10,9 @@ class ContestsController < ApplicationController
|
||||||
def historical
|
def historical
|
||||||
case params[:id]
|
case params[:id]
|
||||||
when "NS1"
|
when "NS1"
|
||||||
@contests = Contest.with_contesters.ordered.where ["name LIKE ? OR name LIKE ?", "S%:%", "%Night%"]
|
@contests = Contest.all.ordered.includes(:contesters).where("name LIKE ? OR name LIKE ?", "S%:%", "%Night%")
|
||||||
else
|
else
|
||||||
@contests = Contest.with_contesters.ordered.where ["id > ?", "113"]
|
@contests = Contest.all.ordered.includes(:contesters).where("id > ?", "113")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ class TeamsController < ApplicationController
|
||||||
before_filter :get_team, only: [:show, :edit, :update, :destroy, :recover]
|
before_filter :get_team, only: [:show, :edit, :update, :destroy, :recover]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@teams = Team.with_teamers_num(0).search(params[:search]).paginate(per_page: 80, page: params[:page]).ordered
|
@teams = Team.non_empty_teams.search(params[:search]).paginate(per_page: 80, page: params[:page]).ordered
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
|
@ -35,30 +35,30 @@ class Contest < ActiveRecord::Base
|
||||||
|
|
||||||
attr_protected :id, :updated_at, :created_at
|
attr_protected :id, :updated_at, :created_at
|
||||||
|
|
||||||
scope :active, :conditions => ["status != ?", STATUS_CLOSED]
|
scope :active, -> { where.not(status: STATUS_CLOSED) }
|
||||||
scope :inactive, :conditions => {:status => STATUS_CLOSED}
|
scope :inactive, -> { where(status: STATUS_CLOSED) }
|
||||||
scope :joinable, :conditions => {:status => STATUS_OPEN}
|
scope :joinable, -> { where(status: STATUS_OPEN) }
|
||||||
scope :with_contesters, :include => :contesters
|
scope :with_contesters, -> { includes(:contesters) }
|
||||||
scope :ordered, :order => "start DESC"
|
scope :ordered, -> { order("start DESC") }
|
||||||
scope :nsls1, :conditions => ["name LIKE ?", "NSL S1:%"]
|
scope :nsls1, -> { where("name LIKE ?", "NSL S1:%") }
|
||||||
scope :nsls2, :conditions => ["name LIKE ?", "NSL S2:%"]
|
scope :nsls2, -> { where("name LIKE ?", "NSL S2:%") }
|
||||||
scope :ns1seasons, :conditions => ["name LIKE ?", "S%:%"]
|
scope :ns1seasons, -> { where("name LIKE ?", "S%:%") }
|
||||||
|
|
||||||
has_many :matches, :dependent => :destroy
|
has_many :matches, :dependent => :destroy
|
||||||
has_many :weeks, :dependent => :destroy
|
has_many :weeks, :dependent => :destroy
|
||||||
has_many :contesters, :dependent => :destroy, :include => :team
|
has_many :contesters, -> { includes(:team) }, :dependent => :destroy
|
||||||
has_many :predictions, :through => :matches
|
has_many :predictions, :through => :matches
|
||||||
has_many :brackets
|
has_many :brackets
|
||||||
has_many :preds_with_score,
|
has_many :preds_with_score, -> {
|
||||||
:source => :predictions,
|
select("predictions.id, predictions.user_id
|
||||||
:through => :matches,
|
SUM(result) AS correct,
|
||||||
:select => "predictions.id, predictions.user_id,
|
SUM(result)/COUNT(*)*100 AS score,
|
||||||
SUM(result) AS correct,
|
COUNT(*) AS total")
|
||||||
SUM(result)/COUNT(*)*100 AS score,
|
.where("result IS NOT NULL")
|
||||||
COUNT(*) AS total",
|
.group("predictions.user_id")
|
||||||
:conditions => "result IS NOT NULL",
|
.order("correct DESC") },
|
||||||
:group => "predictions.user_id",
|
:source => :predictions,
|
||||||
:order => "correct DESC"
|
:through => :matches
|
||||||
has_and_belongs_to_many :maps
|
has_and_belongs_to_many :maps
|
||||||
belongs_to :demos, :class_name => "Directory"
|
belongs_to :demos, :class_name => "Directory"
|
||||||
belongs_to :winner, :class_name => "Contester"
|
belongs_to :winner, :class_name => "Contester"
|
||||||
|
|
|
@ -26,22 +26,24 @@ class Contester < ActiveRecord::Base
|
||||||
attr_protected :id, :updated_at, :created_at, :trend
|
attr_protected :id, :updated_at, :created_at, :trend
|
||||||
attr_accessor :user
|
attr_accessor :user
|
||||||
|
|
||||||
scope :active, :include => :team, :conditions => {"contesters.active" => true}
|
belongs_to :team
|
||||||
|
belongs_to :contest
|
||||||
|
|
||||||
|
scope :active, -> { includes(:team).where(active: true) }
|
||||||
# ranked is used for ladder. lower score the higher the rank
|
# ranked is used for ladder. lower score the higher the rank
|
||||||
scope :ranked, :select => "contesters.*", :order => "score ASC, win DESC, loss ASC"
|
scope :ranked, -> { order("score ASC, win DESC, loss ASC").select("contesters.*") }
|
||||||
scope :ordered, :select => "contesters.*, (score + extra) AS total_score", :order => "total_score DESC, score DESC, win DESC, loss ASC"
|
scope :ordered, -> { select("contesters.*, (score + extra) AS total_score").order("total_score DESC, score DESC, win DESC, loss ASC") }
|
||||||
scope :chronological, :order => "created_at DESC"
|
scope :chronological, -> { order("created_at DESC") }
|
||||||
scope :of_contest, lambda { |contest| {:conditions => {"contesters.contest_id" => contest.id}} }
|
scope :of_contest, -> (contest) { where("contesters.contest_id", contest.id) }
|
||||||
|
|
||||||
has_many :challenges_sent, :class_name => "Challenge", :foreign_key => "contester1_id"
|
has_many :challenges_sent, :class_name => "Challenge", :foreign_key => "contester1_id"
|
||||||
has_many :challenges_received, :class_name => "Challenge", :foreign_key => "contester2_id"
|
has_many :challenges_received, :class_name => "Challenge", :foreign_key => "contester2_id"
|
||||||
has_many :matches, :through => :contest, :conditions => "(contester1_id = contesters.id OR contester2_id = contesters.id)"
|
has_many :matches, -> { where("(contester1_id = contesters.id OR contester2_id = contesters.id)") }, :through => :contest
|
||||||
belongs_to :team
|
|
||||||
belongs_to :contest
|
|
||||||
|
|
||||||
validates_presence_of :team, :contest
|
validates_presence_of :team, :contest
|
||||||
validates_inclusion_of [:score, :win, :loss, :draw, :extra], :in => 0..9999, :allow_nil => true
|
validates_inclusion_of [:score, :win, :loss, :draw, :extra], :in => 0..9999, :allow_nil => true
|
||||||
validates_uniqueness_of :team_id, :scope => :contest_id, :message => "You can't join same contest twice."
|
validates_uniqueness_of :team_id, :scope => :contest_id, :message => "You can't join same contest twice."
|
||||||
|
|
||||||
#validate_on_create:validate_member_participation
|
#validate_on_create:validate_member_participation
|
||||||
#validate_on_create:validate_contest
|
#validate_on_create:validate_contest
|
||||||
#validate_on_create:validate_playernumber
|
#validate_on_create:validate_playernumber
|
||||||
|
@ -93,7 +95,7 @@ class Contester < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_playernumber
|
def validate_playernumber
|
||||||
if team.teamers.active.distinct.count < 6
|
if team.teamers.active.unique_by_team.count < 6
|
||||||
errors.add :team, I18n.t(:contests_join_need6)
|
errors.add :team, I18n.t(:contests_join_need6)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,13 +19,11 @@ class Forum < ActiveRecord::Base
|
||||||
|
|
||||||
attr_protected :id, :updated_at, :created_at
|
attr_protected :id, :updated_at, :created_at
|
||||||
|
|
||||||
scope :public,
|
scope :public_forums, -> { select("forums.*")
|
||||||
:select => "forums.*",
|
.joins("LEFT JOIN forumers ON forumers.forum_id = forums.id AND forumers.access = #{Forumer::ACCESS_READ}")
|
||||||
:joins => "LEFT JOIN forumers ON forumers.forum_id = forums.id AND forumers.access = #{Forumer::ACCESS_READ}",
|
.where("forumers.id IS NULL") }
|
||||||
:conditions => "forumers.id IS NULL"
|
scope :of_forum, -> (forum) { where("forums.id", forum.id) }
|
||||||
scope :of_forum,
|
scope :ordered, -> { order("position") }
|
||||||
lambda { |forum| {:conditions => {"forums.id" => forum.id}} }
|
|
||||||
scope :ordered, :order => "position"
|
|
||||||
|
|
||||||
has_many :topics
|
has_many :topics
|
||||||
has_many :posts, :through => :topics
|
has_many :posts, :through => :topics
|
||||||
|
@ -50,7 +48,7 @@ class Forum < ActiveRecord::Base
|
||||||
if cuser
|
if cuser
|
||||||
Forum.available_to(cuser, Forumer::ACCESS_READ).of_forum(self).first
|
Forum.available_to(cuser, Forumer::ACCESS_READ).of_forum(self).first
|
||||||
else
|
else
|
||||||
Forum.public.of_forum(self).first
|
Forum.public_forums.where(id: self.id).exists?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Gather < ActiveRecord::Base
|
||||||
attr_accessor :admin
|
attr_accessor :admin
|
||||||
|
|
||||||
scope :ordered, -> { order("id DESC") }
|
scope :ordered, -> { order("id DESC") }
|
||||||
scope :basic, -> { include(:captain1, :captain2, :map1, :map2, :server) }
|
scope :basic, -> { includes(:captain1, :captain2, :map1, :map2, :server) }
|
||||||
scope :active, -> { where("gathers.status IN (?, ?, ?) AND gathers.updated_at > ?",
|
scope :active, -> { where("gathers.status IN (?, ?, ?) AND gathers.updated_at > ?",
|
||||||
STATE_VOTING, STATE_PICKING, STATE_RUNNING, 12.hours.ago.utc) }
|
STATE_VOTING, STATE_PICKING, STATE_RUNNING, 12.hours.ago.utc) }
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,11 @@ class Match < ActiveRecord::Base
|
||||||
has_many :matchers, :dependent => :destroy
|
has_many :matchers, :dependent => :destroy
|
||||||
has_many :users, :through => :matchers
|
has_many :users, :through => :matchers
|
||||||
has_many :predictions, :dependent => :destroy
|
has_many :predictions, :dependent => :destroy
|
||||||
has_many :comments, :as => :commentable, :order => "created_at", :dependent => :destroy
|
has_many :comments, -> { order("created_at") }, :as => :commentable, :dependent => :destroy
|
||||||
belongs_to :challenge
|
belongs_to :challenge
|
||||||
belongs_to :contest
|
belongs_to :contest
|
||||||
belongs_to :contester1, :class_name => "Contester", :include => 'team'
|
belongs_to :contester1, -> { includes('team') }, :class_name => "Contester"
|
||||||
belongs_to :contester2, :class_name => "Contester", :include => 'team'
|
belongs_to :contester2, -> { includes('team') }, :class_name => "Contester"
|
||||||
belongs_to :map1, :class_name => "Map"
|
belongs_to :map1, :class_name => "Map"
|
||||||
belongs_to :map2, :class_name => "Map"
|
belongs_to :map2, :class_name => "Map"
|
||||||
belongs_to :server
|
belongs_to :server
|
||||||
|
@ -57,65 +57,41 @@ class Match < ActiveRecord::Base
|
||||||
belongs_to :stream, :class_name => "Movie"
|
belongs_to :stream, :class_name => "Movie"
|
||||||
belongs_to :caster, :class_name => "User"
|
belongs_to :caster, :class_name => "User"
|
||||||
|
|
||||||
scope :future, :conditions => ["match_time > UTC_TIMESTAMP()"]
|
scope :future, -> { where("match_time > UTC_TIMESTAMP()") }
|
||||||
scope :future5, :conditions => ["match_time > UTC_TIMESTAMP()"], :limit => 5
|
scope :future5, -> { where("match_time > UTC_TIMESTAMP()").limit(5) }
|
||||||
scope :finished, :conditions => ["score1 != 0 OR score2 != 0"]
|
scope :finished, -> { where("score1 != 0 OR score2 != 0") }
|
||||||
scope :realfinished, :conditions => ["score1 IS NOT NULL AND score2 IS NOT NULL"]
|
scope :realfinished, -> { where("score1 IS NOT NULL AND score2 IS NOT NULL") }
|
||||||
scope :unfinished, :conditions => ["score1 IS NULL AND score2 IS NULL"]
|
scope :unfinished, -> { where("score1 IS NULL AND score2 IS NULL") }
|
||||||
scope :unreffed, :conditions => ["referee_id IS NULL"]
|
scope :unreffed, -> { where.not(referee_id: nil) }
|
||||||
scope :ordered, :order => "match_time DESC"
|
scope :ordered, -> { order("match_time DESC") }
|
||||||
scope :chrono, :order => "match_time ASC"
|
scope :chrono, -> { order("match_time ASC") }
|
||||||
scope :recent, :limit => "8"
|
scope :recent, -> { limit("8") }
|
||||||
scope :bigrecent, :limit => "50"
|
scope :bigrecent, -> { limit("50") }
|
||||||
scope :active, :conditions => ["contest_id IN (?)", Contest.active]
|
scope :active, -> { where("contest_id IN (?)", Contest.active) }
|
||||||
scope :on_day,
|
scope :on_day, -> (day) { where("match_time > ? and match_time < ?", day.beginning_of_day, day.end_of_day) }
|
||||||
lambda { |day| {
|
scope :on_week, -> (time) { where("match_time > ? and match_time < ?", time.beginning_of_week, time.end_of_week) }
|
||||||
:conditions => ["match_time > ? and match_time < ?", day.beginning_of_day, day.end_of_day]} }
|
scope :of_contester, -> (contester) { where("contester1_id = ? OR contester2_id = ?", contester.id, contester.id) }
|
||||||
scope :on_week,
|
scope :of_user, -> (user) { includes(:matchers).where("matchers.user_id = ?", user.id) }
|
||||||
lambda { |time| {
|
scope :of_team, -> (team) { includes({:contester1 => :team, :contester2 => :team}).where("teams.id = ? OR teams_contesters.id = ?", team.id, team.id) }
|
||||||
:conditions => ["match_time > ? and match_time < ?", time.beginning_of_week, time.end_of_week]} }
|
scope :of_userteam, -> (user, team) { includes({:matchers => {:contester => :team}}).where("teams.id = ? AND matchers.user_id = ?", team.id, user.id) }
|
||||||
scope :of_contester,
|
scope :within_time, -> (from, to) { where("match_time > ? AND match_time < ?", from.utc, to.utc) }
|
||||||
lambda { |contester| {
|
scope :around, -> (time) { where("match_time > ? AND match_time < ?", time.ago(MATCH_LENGTH).utc, time.ago(-MATCH_LENGTH).utc) }
|
||||||
:conditions => ["contester1_id = ? OR contester2_id = ?", contester.id, contester.id]} }
|
scope :after, -> (time) { where("match_time > ? AND match_time < ?", time.utc, time.ago(-MATCH_LENGTH).utc) }
|
||||||
scope :of_user,
|
scope :map_stats, -> { select("map1_id, COUNT(*) as num, maps.name").
|
||||||
lambda { |user| {
|
joins("LEFT JOIN maps ON maps.id = map1_id").
|
||||||
:include => :matchers,
|
group("map1_id").
|
||||||
:conditions => ["matchers.user_id = ?", user.id]} }
|
having("map1_id is not null").
|
||||||
scope :of_team,
|
order("num DESC") }
|
||||||
lambda { |team| {
|
scope :year_stats, -> { select("id, DATE_FORMAT(match_time, '%Y') as year, COUNT(*) as num").
|
||||||
:include => {:contester1 => :team,
|
where("match_time > '2000-01-01 01:01:01'").
|
||||||
:contester2 => :team}, :conditions => ["teams.id = ? OR teams_contesters.id = ?", team.id, team.id]} }
|
group("year").
|
||||||
scope :of_userteam,
|
order("num DESC") }
|
||||||
lambda { |user, team| {
|
scope :month_stats, -> { select("id, DATE_FORMAT(match_time, '%m') as month_n,
|
||||||
:include => {:matchers => {:contester => :team}},
|
DATE_FORMAT(match_time, '%M') as month,
|
||||||
:conditions => ["teams.id = ? AND matchers.user_id = ?", team.id, user.id]} }
|
COUNT(*) as num").
|
||||||
scope :within_time,
|
where("match_time > '2000-01-01 01:01:01'").
|
||||||
lambda { |from, to| {
|
group("month").
|
||||||
:conditions => ["match_time > ? AND match_time < ?", from.utc, to.utc]} }
|
order("month_n") }
|
||||||
scope :around,
|
|
||||||
lambda { |time| {
|
|
||||||
:conditions => ["match_time > ? AND match_time < ?", time.ago(MATCH_LENGTH).utc, time.ago(-MATCH_LENGTH).utc]} }
|
|
||||||
scope :after,
|
|
||||||
lambda { |time| {
|
|
||||||
:conditions => ["match_time > ? AND match_time < ?", time.utc, time.ago(-MATCH_LENGTH).utc]} }
|
|
||||||
scope :map_stats,
|
|
||||||
:select => "map1_id, COUNT(*) as num, maps.name",
|
|
||||||
:joins => "LEFT JOIN maps ON maps.id = map1_id",
|
|
||||||
:group => "map1_id",
|
|
||||||
:having => "map1_id is not null",
|
|
||||||
:order => "num DESC"
|
|
||||||
scope :year_stats,
|
|
||||||
:select => "id, DATE_FORMAT(match_time, '%Y') as year, COUNT(*) as num",
|
|
||||||
:conditions => "match_time > '2000-01-01 01:01:01'",
|
|
||||||
:group => "year",
|
|
||||||
:order => "num DESC"
|
|
||||||
scope :month_stats,
|
|
||||||
:select => "id, DATE_FORMAT(match_time, '%m') as month_n,
|
|
||||||
DATE_FORMAT(match_time, '%M') as month,
|
|
||||||
COUNT(*) as num",
|
|
||||||
:conditions => "match_time > '2000-01-01 01:01:01'",
|
|
||||||
:group => "month",
|
|
||||||
:order => "month_n"
|
|
||||||
|
|
||||||
validates_presence_of :contester1, :contester2, :contest
|
validates_presence_of :contester1, :contester2, :contest
|
||||||
validates_format_of [:score1, :score2], :with => /\A[0-9]\z/, :allow_nil => true
|
validates_format_of [:score1, :score2], :with => /\A[0-9]\z/, :allow_nil => true
|
||||||
|
@ -145,12 +121,12 @@ class Match < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def preds contester
|
def preds contester
|
||||||
perc = Prediction.count(:conditions => ["match_id = ? AND score#{contester} > 2", id])
|
perc = Prediction.where("match_id = ? AND score#{contester} > 2", id).count()
|
||||||
perc != 0 ? (perc/predictions.count.to_f*100).round : 0
|
perc != 0 ? (perc/predictions.count.to_f*100).round : 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def mercs contester
|
def mercs contester
|
||||||
matchers.all :conditions => {:merc => true, :contester_id => contester.id}
|
matchers.where(merc: true, contester_id: contester.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_hltv
|
def get_hltv
|
||||||
|
@ -162,11 +138,11 @@ class Match < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def team1_lineup
|
def team1_lineup
|
||||||
matchers.all(:conditions => {:contester_id => contester1_id})
|
matchers.where(contester_id: contester1_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def team2_lineup
|
def team2_lineup
|
||||||
matchers.all(:conditions => {:contester_id => contester2_id})
|
matchers.where(contester_id: contester2_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_friendly param = nil
|
def get_friendly param = nil
|
||||||
|
@ -194,7 +170,7 @@ class Match < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_notifications
|
def send_notifications
|
||||||
Profile.all(:include => :user, :conditions => "notify_any_match = 1").each do |p|
|
Profile.where("notify_any_match", 1).includes(:user).each do |p|
|
||||||
Notifications.match p.user, self if p.user
|
Notifications.match p.user, self if p.user
|
||||||
end
|
end
|
||||||
contester2.team.teamers.active.each do |teamer|
|
contester2.team.teamers.active.each do |teamer|
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
# category_id :integer
|
# category_id :integer
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'data_file'
|
|
||||||
|
|
||||||
class Movie < ActiveRecord::Base
|
class Movie < ActiveRecord::Base
|
||||||
include Extra
|
include Extra
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
class Poll < ActiveRecord::Base
|
class Poll < ActiveRecord::Base
|
||||||
include Extra
|
include Extra
|
||||||
|
|
||||||
|
default_scope -> { order("created_at DESC") }
|
||||||
|
|
||||||
attr_protected :id, :updated_at, :created_at, :votes, :user_id
|
attr_protected :id, :updated_at, :created_at, :votes, :user_id
|
||||||
|
|
||||||
validates_length_of :question, :in => 1..50
|
validates_length_of :question, :in => 1..50
|
||||||
|
|
|
@ -33,33 +33,36 @@ class Team < ActiveRecord::Base
|
||||||
validates_format_of :country, :with => /\A[A-Z]{2}\z/, :allow_blank => true
|
validates_format_of :country, :with => /\A[A-Z]{2}\z/, :allow_blank => true
|
||||||
validates_length_of [:comment, :recruiting], :in => 0..75, :allow_blank => true
|
validates_length_of [:comment, :recruiting], :in => 0..75, :allow_blank => true
|
||||||
|
|
||||||
scope :with_teamers_num,
|
scope :with_teamers_num, -> (num) {
|
||||||
lambda { |num| {
|
select("teams.*, COUNT(T.id) AS teamers_num").
|
||||||
:select => "teams.*, COUNT(T.id) AS teamers_num",
|
joins("LEFT JOIN teamers T ON T.team_id = teams.id AND T.rank >= #{Teamer::RANK_MEMBER}").
|
||||||
:joins => "LEFT JOIN teamers T ON T.team_id = teams.id AND T.rank >= #{Teamer::RANK_MEMBER}",
|
group("teams.id").
|
||||||
:group => "teams.id",
|
having("teamers_num >= ?", num) }
|
||||||
:having => ["teamers_num >= ?", num]} }
|
scope :non_empty_teams, -> { joins(:teamers).where("teamers.rank >= #{Teamer::RANK_MEMBER}").distinct }
|
||||||
scope :with_teamers, :include => :teamers
|
scope :with_teamers, -> { includes(:teamers) }
|
||||||
scope :active, :conditions => {:active => true}
|
scope :active, -> { where(active: true) }
|
||||||
scope :inactive, :conditions => {:active => false}
|
scope :inactive, -> { where(active: false) }
|
||||||
scope :ordered, :order => "name"
|
scope :ordered, -> { order("name") }
|
||||||
scope :recruiting, :conditions => "recruiting IS NOT NULL AND recruiting != ''"
|
scope :recruiting, -> { where("recruiting IS NOT NULL AND recruiting != ''") }
|
||||||
|
|
||||||
belongs_to :founder, :class_name => "User"
|
belongs_to :founder, :class_name => "User"
|
||||||
|
|
||||||
|
has_many :active_teamers, -> { where("rank >= ?", Teamer::RANK_MEMBER) }
|
||||||
has_many :teamers, :dependent => :destroy
|
has_many :teamers, :dependent => :destroy
|
||||||
has_many :leaders, :class_name => "Teamer", :conditions => ["rank = ?", Teamer::RANK_LEADER]
|
has_many :leaders, -> { where("rank = ?", Teamer::RANK_LEADER) }, :class_name => "Teamer"
|
||||||
has_many :contesters, :dependent => :destroy
|
has_many :contesters, :dependent => :destroy
|
||||||
has_many :contests, :through => :contesters, :conditions => {"contesters.active" => true}
|
has_many :contests, -> { where("contesters.active", true) }, :through => :contesters
|
||||||
has_many :received_messages, :class_name => "Message", :as => "recipient"
|
has_many :received_messages, :class_name => "Message", :as => "recipient"
|
||||||
has_many :sent_messages, :class_name => "Message", :as => "sender"
|
has_many :sent_messages, :class_name => "Message", :as => "sender"
|
||||||
has_many :matches, :through => :contesters
|
has_many :matches, :through => :contesters
|
||||||
has_many :matches_finished, :through => :contesters, :source => :matches, :conditions => "(score1 != 0 OR score2 != 0)"
|
has_many :matches_finished, -> { where("(score1 != 0 OR score2 != 0)") },
|
||||||
has_many :matches_won, :through => :contesters, :source => :matches,
|
:through => :contesters, :source => :matches
|
||||||
:conditions => "((score1 > score2 AND contester1_id = contesters.id) OR (score2 > score1 AND contester2_id = contesters.id)) AND (score1 != 0 OR score2 != 0)"
|
has_many :matches_won, -> { where("((score1 > score2 AND contester1_id = contesters.id) OR (score2 > score1 AND contester2_id = contesters.id)) AND (score1 != 0 OR score2 != 0)") },
|
||||||
has_many :matches_lost, :through => :contesters, :source => :matches,
|
:through => :contesters, :source => :matches
|
||||||
:conditions => "((score1 < score2 AND contester1_id = contesters.id) OR (score2 < score1 AND contester2_id = contesters.id)) AND (score1 != 0 OR score2 != 0)"
|
has_many :matches_lost, -> { where("((score1 < score2 AND contester1_id = contesters.id) OR (score2 < score1 AND contester2_id = contesters.id)) AND (score1 != 0 OR score2 != 0)") },
|
||||||
has_many :matches_draw, :through => :contesters, :source => :matches,
|
:through => :contesters, :source => :matches
|
||||||
:conditions => "(score1 = score2 AND score1 > 0) AND (score1 != 0 OR score2 != 0)"
|
has_many :matches_draw, -> { where("(score1 = score2 AND score1 > 0) AND (score1 != 0 OR score2 != 0)") },
|
||||||
|
:through => :contesters, :source => :matches
|
||||||
|
|
||||||
mount_uploader :logo, TeamUploader
|
mount_uploader :logo, TeamUploader
|
||||||
|
|
||||||
|
@ -89,7 +92,7 @@ class Team < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search(search)
|
def self.search(search)
|
||||||
search ? where("LOWER(name) LIKE LOWER(?)", "%#{search}%") : scoped
|
search ? where("LOWER(name) LIKE LOWER(?)", "%#{search}%") : all
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
@ -29,80 +29,67 @@ class Teamer < ActiveRecord::Base
|
||||||
#validate_on_create:validate_contests
|
#validate_on_create:validate_contests
|
||||||
validate :validate_team
|
validate :validate_team
|
||||||
|
|
||||||
scope :basic,
|
scope :basic, -> { includes(:user).order("rank DESC, created_at ASC") }
|
||||||
:include => :user,
|
scope :past, -> { where("teamers.rank = ?", RANK_REMOVED) }
|
||||||
:order => "rank DESC, created_at ASC"
|
scope :joining,-> { where("teamers.rank = ?", RANK_JOINER) }
|
||||||
scope :past,
|
scope :present, -> { where("teamers.rank >= ?", RANK_JOINER) }
|
||||||
:conditions => ["teamers.rank = ?", RANK_REMOVED]
|
scope :active, -> { where("teamers.rank >= ?", RANK_MEMBER) }
|
||||||
scope :joining,
|
scope :leaders, -> { where("teamers.rank >= ?", RANK_DEPUTEE) }
|
||||||
:conditions => ["teamers.rank = ?", RANK_JOINER]
|
scope :of_team, -> (team) { where("teamers.team_id" => team.id) }
|
||||||
scope :present,
|
scope :active_teams, -> { includes(:team).where("teams.active = ?", true) }
|
||||||
:conditions => ["teamers.rank >= ?", RANK_JOINER]
|
scope :unique_by_team, -> { group("user_id, team_id") }
|
||||||
scope :active,
|
scope :ordered, -> { order("rank DESC, created_at ASC") }
|
||||||
:conditions => ["teamers.rank >= ?", RANK_MEMBER]
|
scope :historic, -> (user, time) {
|
||||||
scope :leaders,
|
where("user_id = ? AND created_at < ? AND ((updated_at > ? AND rank = ?) OR rank >= ?)",
|
||||||
:conditions => ["teamers.rank >= ?", RANK_DEPUTEE]
|
user.id, time.utc, time.utc, RANK_REMOVED, RANK_MEMBER) }
|
||||||
scope :of_team,
|
|
||||||
lambda { |team| {:conditions => {"teamers.team_id" => team.id}} }
|
|
||||||
scope :active_teams,
|
|
||||||
:include => :team,
|
|
||||||
:conditions => ["teams.active = ?", true]
|
|
||||||
scope :distinct,
|
|
||||||
:group => "user_id, team_id"
|
|
||||||
scope :ordered,
|
|
||||||
:order => "rank DESC, created_at ASC"
|
|
||||||
scope :historic,
|
|
||||||
lambda { |user, time|
|
|
||||||
{:conditions => ["user_id = ? AND created_at < ? AND ((updated_at > ? AND rank = ?) OR rank >= ?)",
|
|
||||||
user.id, time.utc, time.utc, RANK_REMOVED, RANK_MEMBER]} }
|
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :team
|
belongs_to :team
|
||||||
has_many :other_teamers, :through => :user, :source => :teamers, :conditions => ["teamers.id != ?", object_id]
|
has_many :other_teamers, -> { where("teamers.id != ?", object_id) }, :through => :user, :source => :teamers
|
||||||
has_many :contesters, :through => :team
|
has_many :contesters, :through => :team
|
||||||
|
|
||||||
before_create :init_variables
|
before_create :init_variables
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
user.to_s
|
user.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def ranks
|
||||||
|
{RANK_JOINER => "Joining", RANK_MEMBER => "Member", RANK_DEPUTEE => "Deputee", RANK_LEADER => "Leader"}
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_team
|
||||||
|
if user.teamers.of_team(team).present.count > 0
|
||||||
|
errors.add :team, I18n.t(:teams_join_twice)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def ranks
|
def validate_contests
|
||||||
{RANK_JOINER => "Joining", RANK_MEMBER => "Member", RANK_DEPUTEE => "Deputee", RANK_LEADER => "Leader"}
|
# TODO
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_team
|
def init_variables
|
||||||
if user.teamers.of_team(team).present.count > 0
|
self.rank = RANK_JOINER unless self.rank
|
||||||
errors.add :team, I18n.t(:teams_join_twice)
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_contests
|
def destroy
|
||||||
# TODO
|
user.update_attribute :team, nil if user.team == team
|
||||||
|
if rank == Teamer::RANK_JOINER
|
||||||
|
super
|
||||||
|
else
|
||||||
|
update_attribute :rank, Teamer::RANK_REMOVED
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def init_variables
|
def can_create? cuser, params
|
||||||
self.rank = RANK_JOINER unless self.rank
|
cuser and Verification.contain params, [:user_id, :team_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def can_update? cuser
|
||||||
user.update_attribute :team, nil if user.team == team
|
cuser and cuser.admin?
|
||||||
if rank == Teamer::RANK_JOINER
|
end
|
||||||
super
|
|
||||||
else
|
|
||||||
update_attribute :rank, Teamer::RANK_REMOVED
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def can_create? cuser, params
|
def can_destroy? cuser
|
||||||
cuser and Verification.contain params, [:user_id, :team_id]
|
cuser and (user == cuser or team.is_leader? cuser or cuser.admin?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_update? cuser
|
|
||||||
cuser and cuser.admin?
|
|
||||||
end
|
|
||||||
|
|
||||||
def can_destroy? cuser
|
|
||||||
cuser and (user == cuser or team.is_leader? cuser or cuser.admin?)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,23 +90,23 @@ class User < ActiveRecord::Base
|
||||||
.joins("LEFT JOIN posts ON posts.user_id = users.id")
|
.joins("LEFT JOIN posts ON posts.user_id = users.id")
|
||||||
.group("users.id")
|
.group("users.id")
|
||||||
.order("num DESC") }
|
.order("num DESC") }
|
||||||
scope :banned,
|
scope :banned, -> {
|
||||||
:joins => "LEFT JOIN bans ON bans.user_id = users.id AND expiry > UTC_TIMESTAMP()",
|
joins("LEFT JOIN bans ON bans.user_id = users.id AND expiry > UTC_TIMESTAMP()")
|
||||||
:conditions => "bans.id IS NOT NULL"
|
.conditions("bans.id IS NOT NULL") }
|
||||||
scope :idle,
|
scope :idle, -> {
|
||||||
:conditions => ["lastvisit < ?", 30.minutes.ago.utc]
|
joins("lastvisit < ?", 30.minutes.ago.utc) }
|
||||||
|
|
||||||
validates_uniqueness_of :username, :email, :steamid
|
validates_uniqueness_of :username, :email, :steamid
|
||||||
validates_length_of :firstname, :in => 1..15, :allow_blank => true
|
validates_length_of :firstname, :in => 1..15, :allow_blank => true
|
||||||
validates_length_of :lastname, :in => 1..25, :allow_blank => true
|
validates_length_of :lastname, :in => 1..25, :allow_blank => true
|
||||||
validates_length_of :username, :in => 2..20
|
validates_length_of :username, :in => 2..20
|
||||||
validates_format_of :username, :with => /\A[A-Za-z0-9_\-\+]{2,20}\Z/
|
validates_format_of :username, :with => /\A[A-Za-z0-9_\-\+]{2,20}\Z/
|
||||||
validates_presence_of :raw_password, :on => :create
|
validates_presence_of :raw_password, :on => :create
|
||||||
validates_length_of :email, :maximum => 50
|
validates_length_of :email, :maximum => 50
|
||||||
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
||||||
validates_length_of :steamid, :maximum => 30
|
validates_length_of :steamid, :maximum => 30
|
||||||
validates_format_of :steamid, :with => /\A([0-9]{1,10}:){2}[0-9]{1,10}\Z/
|
validates_format_of :steamid, :with => /\A([0-9]{1,10}:){2}[0-9]{1,10}\Z/
|
||||||
validates_length_of :time_zone, :maximum => 100, :allow_blank => true, :allow_nil => true
|
validates_length_of :time_zone, :maximum => 100, :allow_blank => true, :allow_nil => true
|
||||||
validates_inclusion_of [:public_email], :in => [true, false], :allow_nil => true
|
validates_inclusion_of [:public_email], :in => [true, false], :allow_nil => true
|
||||||
validate :validate_team
|
validate :validate_team
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search(search)
|
def self.search(search)
|
||||||
search ? where("LOWER(username) LIKE LOWER(?) OR steamid LIKE ?", "%#{search}%", "%#{search}%") : scoped
|
search ? where("LOWER(username) LIKE LOWER(?) OR steamid LIKE ?", "%#{search}%", "%#{search}%") : all
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.refadmins
|
def self.refadmins
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<div id="categories">
|
<div id="categories">
|
||||||
<% @categories.each do |cat| %>
|
<% @categories.each do |cat| %>
|
||||||
<% forums = cuser ? cat.forums.available_to(cuser, Forumer::ACCESS_READ).ordered : cat.forums.public.ordered %>
|
<% forums = cuser ? cat.forums.available_to(cuser, Forumer::ACCESS_READ).ordered : cat.forums.public_forums.ordered %>
|
||||||
<% next if forums.length == 0 %>
|
<% next if forums.length == 0 %>
|
||||||
|
|
||||||
<div class="category">
|
<div class="category">
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
<strong><%= Topic.count %></strong> topics, and <strong><%= User.count %></strong> users.
|
<strong><%= Topic.count %></strong> topics, and <strong><%= User.count %></strong> users.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Our newest member is <%= namelink User.last %> and most active member is <%= namelink User.posts_stats.first %>.
|
Our newest member is <%= namelink User.last %> and most active member is <%= namelink User.posts_stats(1).first %>.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% for team in teams %>
|
<% for team in teams %>
|
||||||
<% if team.teamers_num > 0 %>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= flag team.country %></td>
|
<td><%= flag team.country %></td>
|
||||||
<td><%= namelink team %></td>
|
<td><%= namelink team %></td>
|
||||||
|
@ -33,6 +32,5 @@
|
||||||
</td>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -58,14 +58,14 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tab" id="members">
|
<div class="tab" id="members">
|
||||||
<% if @team.teamers.active.ordered.distinct.length > 0 %>
|
<% if @team.teamers.active.ordered.unique_by_team.length > 0 %>
|
||||||
<h3>Current Members</h3>
|
<h3>Current Members</h3>
|
||||||
<%= render partial: "teamers/list", locals: { teamers: @team.teamers.active.ordered.distinct, blacklist: false, comment: true } %>
|
<%= render partial: "teamers/list", locals: { teamers: @team.teamers.active.ordered.unique_by_team, blacklist: false, comment: true } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @team.teamers.past.distinct.length > 0 %>
|
<% if @team.teamers.past.unique_by_team.length > 0 %>
|
||||||
<h3>Past Members</h3>
|
<h3>Past Members</h3>
|
||||||
<%= render partial: "teamers/list", locals: { teamers: @team.teamers.past.distinct, blacklist: @team.teamers.active.ordered.distinct, comment: false } %>
|
<%= render partial: "teamers/list", locals: { teamers: @team.teamers.past.unique_by_team, blacklist: @team.teamers.active.ordered.unique_by_team, comment: false } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<div class="widget poll">
|
<div class="widget poll">
|
||||||
<h4><%= t('widget.poll') %></h4>
|
<h4><%= t('widget.poll') %></h4>
|
||||||
|
|
||||||
<% @poll = Poll.first(order: "created_at DESC") %>
|
<% @poll = Poll.first %>
|
||||||
<%= render(partial: "polls/show") if @poll %>
|
<%= render(partial: "polls/show") if @poll %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
3
bin/bundle
Executable file
3
bin/bundle
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
||||||
|
load Gem.bin_path('bundler', 'bundle')
|
4
bin/rails
Executable file
4
bin/rails
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
||||||
|
require_relative '../config/boot'
|
||||||
|
require 'rails/commands'
|
4
bin/rake
Executable file
4
bin/rake
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
require_relative '../config/boot'
|
||||||
|
require 'rake'
|
||||||
|
Rake.application.run
|
Loading…
Reference in a new issue