Skip to content

Commit

Permalink
Fix: Bugs fixed for redmine3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jongha committed Mar 5, 2015
1 parent d793ccb commit 7488442
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions app/models/votes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class Votes < ActiveRecord::Base
unloadable

def add_vote(message_id, user_id, point = 0)
votes = Votes.find(:first, :conditions => ['message_id = ? and user_id = ?', message_id, user_id])
if votes
votes = Votes.where('message_id = %d and user_id = %d' % [message_id, user_id]).limit(1)

unless votes.count == 0
votes.point = point.nil? ? 0 : point
votes.save!
else
Expand All @@ -13,20 +14,20 @@ def add_vote(message_id, user_id, point = 0)
votes.point = point.nil? ? 0 : point
votes.save!
end

return get_point(message_id)
end

def get_point(message_id)
return Votes.sum(:point, :conditions => ['message_id = ?', message_id])
return Votes.where('message_id = %d' % message_id).sum(:point)
end

def get_points(user_id, message_id)
return result = {
"plus" => Votes.sum(:point, :conditions => ['message_id = ? and point > 0', message_id]),
"minus" => Votes.sum(:point, :conditions => ['message_id = ? and point < 0', message_id]),
"zero" => Votes.sum(:point, :conditions => ['message_id = ? and point = 0', message_id]),
"vote" => Votes.count(:point, :conditions => ['message_id = ? and user_id = ?', message_id, user_id]),
"plus" => Votes.where('message_id = %d and point > 0' % message_id).sum(:point),
"minus" => Votes.where('message_id = %d and point < 0' % message_id).sum(:point),
"zero" => Votes.where('message_id = %d and point = 0' % message_id).sum(:point),
"vote" => Votes.where('message_id = %d and user_id = %d' % [message_id, user_id]).count(:point),
}
end
end
end
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name 'Redmine Vote plugin'
author 'Jong-Ha Ahn'
description 'This is a plugin for Redmine'
version '1.2.1'
version '1.2.2'
url 'http://github.com/jongha/redmine_vote'
author_url 'http://www.mrlatte.net'
end

0 comments on commit 7488442

Please sign in to comment.