implement super voters

This commit is contained in:
r888888888
2016-02-22 14:02:52 -08:00
parent caf4a28b02
commit 2a87aad34e
13 changed files with 189 additions and 12 deletions

View File

@@ -952,14 +952,22 @@ class Post < ActiveRecord::Base
!PostVote.exists?(:user_id => user.id, :post_id => id)
end
def vote_magnitude
if CurrentUser.is_super_voter?
SuperVoter::MAGNITUDE
else
1
end
end
def vote!(score)
if can_be_voted_by?(CurrentUser.user)
if score == "up"
Post.where(:id => id).update_all("score = score + 1, up_score = up_score + 1")
self.score += 1
Post.where(:id => id).update_all("score = score + #{vote_magnitude}, up_score = up_score + #{vote_magnitude}")
self.score += vote_magnitude
elsif score == "down"
Post.where(:id => id).update_all("score = score - 1, down_score = down_score - 1")
self.score -= 1
Post.where(:id => id).update_all("score = score - #{vote_magnitude}, down_score = down_score - #{vote_magnitude}")
self.score -= vote_magnitude
end
votes.create(:score => score)
@@ -975,11 +983,11 @@ class Post < ActiveRecord::Base
vote = votes.where("user_id = ?", CurrentUser.user.id).first
if vote.score == 1
Post.where(:id => id).update_all("score = score - 1, up_score = up_score - 1")
self.score -= 1
Post.where(:id => id).update_all("score = score - #{vote_magnitude}, up_score = up_score - #{vote_magnitude}")
self.score -= vote_magnitude
else
Post.where(:id => id).update_all("score = score + 1, down_score = down_score + 1")
self.score += 1
Post.where(:id => id).update_all("score = score + #{vote_magnitude}, down_score = down_score + #{vote_magnitude}")
self.score += vote_magnitude
end
vote.destroy