summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/bracket.rb7
-rw-r--r--app/models/tournament.rb17
-rw-r--r--app/models/tournament_stage.rb52
-rw-r--r--app/models/user.rb4
4 files changed, 42 insertions, 38 deletions
diff --git a/app/models/bracket.rb b/app/models/bracket.rb
index e8d9c5a..acd33ca 100644
--- a/app/models/bracket.rb
+++ b/app/models/bracket.rb
@@ -1,4 +1,11 @@
class Bracket < ActiveRecord::Base
belongs_to :user
belongs_to :tournament
+ has_many :bracket_matches
+
+ def create_matches
+ tournament.stages.first.matches.each do |m|
+ bracket_matches.create(match: m)
+ end
+ end
end
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 861be6c..61b4700 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -1,10 +1,13 @@
class Tournament < ActiveRecord::Base
belongs_to :game
has_many :stages, class_name: "TournamentStage"
+ has_many :brackets
has_many :settings_raw, class_name: "TournamentSetting"
has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments"
has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments"
+ # Settings #################################################################
+
def settings
@settings ||= Settings.new(self)
end
@@ -56,10 +59,14 @@ class Tournament < ActiveRecord::Base
end
end
+ # Misc. ####################################################################
+
def open?
return true
end
+ # Joining/Leaving ##########################################################
+
def joinable_by?(user)
return (open? and user.can?(:join_tournament) and !players.include?(user))
end
@@ -76,4 +83,14 @@ class Tournament < ActiveRecord::Base
players.delete(user)
end
end
+
+ # Configured methods #######################################################
+
+ def scoring
+ @scoring ||= "Scoring::#{self.scoring_method.camelcase}".constantize
+ end
+
+ def sampling
+ @sampling ||= "Sampling::#{self.sampling_method.camelcase}".constantize
+ end
end
diff --git a/app/models/tournament_stage.rb b/app/models/tournament_stage.rb
index 0775305..9352137 100644
--- a/app/models/tournament_stage.rb
+++ b/app/models/tournament_stage.rb
@@ -2,6 +2,7 @@ class TournamentStage < ActiveRecord::Base
belongs_to :tournament
has_many :matches
+ # A 1-indexed hash of matches
def matches_ordered
h = {}
i = 1
@@ -13,57 +14,32 @@ class TournamentStage < ActiveRecord::Base
end
def create_matches
- set_scheduling
- @scheduling.create_matches
+ scheduling.create_matches
end
def to_svg(highlight_user)
- set_scheduling
- return @scheduling.graph(highlight_user)
+ return scheduling.graph(highlight_user)
end
- def pair
- set_pairing
- return @pairing.pair(matches, players)
+ def seed
+ return seeding.seed.pair(matches, players)
end
- def score
- set_scoring
- #populating the user scores in the database form what you get from @scoring.score(match, interface)
- end
+ # Accessors to the configured methods
- #populate the statistics interface (with populating method)
- def populate
- set_populating
- #?
+ def scoring
+ @scoring ||= tournament.scoring
end
- private
- def set_scheduling
- if @scheduling.nil?
- @scheduling = "Scheduling::#{self.scheduling.capitalize}".constantize.new(self)
- end
- return @scheduling
- end
-
- private
- def set_pairing
- if @pairing.nil?
- if(@tournament.randomized_teams)
- @pairing = "Pairing::RandomPairing"
- #elsif(setTeams)
- #@pairing = Pre built
- #return @pairing
- end
- end
- return @pairing
+ def sampling
+ @sampling ||= tournament.sampling
end
- private
- def set_scoring
+ def scheduling
+ @scheduling ||= "Scheduling::#{self.scheduling_method.camelcase}".constantize.new(self)
end
- private
- def set_populating
+ def seeding
+ @seeding ||= "Seeding::#{self.seeding_method.camelcase}".constantize.new(self)
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index d87f988..b2c7862 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -74,6 +74,10 @@ class User < ActiveRecord::Base
:edit_permissions => (2**19),
:edit_server => (2**20),
+
+ :create_bracket => (2**21),
+ :edit_bracket => (2**22),
+ :delete_bracket => (2**23)
}
end