summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authornfoy <nfoy@purdue.edu>2014-03-06 20:40:18 -0500
committernfoy <nfoy@purdue.edu>2014-03-06 20:40:18 -0500
commita892016443d4845c1f738bcc57db82174c53701c (patch)
treef05cfe552d4b7c6793b172aa6b92906a0b2241fa /app/models
parente10bf58ec059ec263c1d1a9dcac608475377868a (diff)
parent7bcd854443e368806cf1f4ece562c157db723d1a (diff)
Merge branch 'master' of https://github.com/LukeShu/leaguer
Conflicts: config/routes.rb
Diffstat (limited to 'app/models')
-rw-r--r--app/models/tournament.rb22
-rw-r--r--app/models/user.rb2
-rw-r--r--app/models/user_tournament_pair.rb4
3 files changed, 26 insertions, 2 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 5e8ddfe..26dec72 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -1,4 +1,22 @@
class Tournament < ActiveRecord::Base
- belongs_to :game
- has_many :matches
+ belongs_to :game
+ has_many :matches
+ has_many :user_tournament_pairs
+ has_many :users, :through => :user_tournament_pairs
+
+ def open?
+ return true
+ end
+
+ def joinable_by?(user)
+ return ((not user.nil?) and user.in_group?(:player) and open?)
+ end
+
+ def join(user)
+ unless joinable_by?(user)
+ return false
+ end
+ pair = UserTournamentPair.new(tournament: self, user: user)
+ return pair.save
+ end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 9288ef6..bad7f7b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,4 +1,6 @@
class User < ActiveRecord::Base
+ has_many :user_tournament_pairs
+ has_many :tournaments, :through => :user_tournament_pairs
before_save { self.email = email.downcase }
before_save { self.user_name = user_name }
diff --git a/app/models/user_tournament_pair.rb b/app/models/user_tournament_pair.rb
new file mode 100644
index 0000000..b2676e5
--- /dev/null
+++ b/app/models/user_tournament_pair.rb
@@ -0,0 +1,4 @@
+class UserTournamentPair < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :tournament
+end