diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-07-20 20:45:16 +0200 |
---|---|---|
committer | Petteri Räty <petsku@petteriraty.eu> | 2011-08-03 12:51:57 +0300 |
commit | 33abbf833236f957ff49d46951ee0dad294c677e (patch) | |
tree | 27f53754b62c7de3045af7a917cf425f7143c5ee /site/app/models/vote.rb | |
parent | Make some more actions available only to council members (diff) | |
download | council-webapp-33abbf833236f957ff49d46951ee0dad294c677e.tar.gz council-webapp-33abbf833236f957ff49d46951ee0dad294c677e.tar.bz2 council-webapp-33abbf833236f957ff49d46951ee0dad294c677e.zip |
Custom doodle-like feature
Diffstat (limited to 'site/app/models/vote.rb')
-rw-r--r-- | site/app/models/vote.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/site/app/models/vote.rb b/site/app/models/vote.rb index 7aea160..a8b63f0 100644 --- a/site/app/models/vote.rb +++ b/site/app/models/vote.rb @@ -68,11 +68,25 @@ class Vote < ActiveRecord::Base end end + def self.update_user_poll_votes(new_choice, user, item) + old_choice = Vote.user_is(user).for_item(item).*.voting_option_id + (old_choice - new_choice).each do |choice_id| + vote = Vote.user_is(user).voting_option_is(choice_id).first + next if vote.nil? + vote.destroy + end + + (new_choice - old_choice).each do |choice_id| + next unless VotingOption.find(choice_id).agenda_item_is?(item) + Vote.create! :user => user, :voting_option_id => choice_id + end + end protected def user_voted_only_once return if user.nil? return if voting_option.nil? return if voting_option.agenda_item.nil? + return if voting_option.agenda_item.poll other_votes = Vote.for_item(voting_option.agenda_item_id).user_id_is(user_id) other_votes = other_votes.id_is_not(id) unless new_record? if other_votes.count > 0 |