Class: Decidim::Votings::Voting
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Decidim::Votings::Voting
- Includes:
- Followable, HasAttachmentCollections, HasAttachments, HasUploadValidations, Participable, ParticipatorySpaceResourceable, Publicable, Randomable, ScopableParticipatorySpace, Searchable, TranslatableResource, Loggable, Traceable
- Defined in:
- app/models/decidim/votings/voting.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #attachment_context ⇒ Object
- #available_polling_officers ⇒ Object
-
#complete_election_data(election, election_data) ⇒ Object
Methods for Votings Space <-> Elections Component interaction.
- #cta_button_text_key ⇒ Object
- #elections ⇒ Object
- #finished? ⇒ Boolean
- #has_ballot_styles? ⇒ Boolean
- #period_status ⇒ Object
- #polling_stations_with_missing_officers? ⇒ Boolean
- #published_elections ⇒ Object
- #scopes_enabled ⇒ Object
- #to_param ⇒ Object
- #upcoming? ⇒ Boolean
- #vote_flow_for(election) ⇒ Object
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
97 98 99 |
# File 'app/models/decidim/votings/voting.rb', line 97 def self.log_presenter_class_for(_log) Decidim::Votings::AdminLog::VotingPresenter end |
Instance Method Details
#active? ⇒ Boolean
69 70 71 |
# File 'app/models/decidim/votings/voting.rb', line 69 def active? start_time <= Time.now.utc && end_time >= Time.now.utc end |
#attachment_context ⇒ Object
116 117 118 |
# File 'app/models/decidim/votings/voting.rb', line 116 def :admin end |
#available_polling_officers ⇒ Object
128 129 130 131 132 |
# File 'app/models/decidim/votings/voting.rb', line 128 def available_polling_officers polling_officers .where(presided_polling_station_id: nil) .where(managed_polling_station_id: nil) end |
#complete_election_data(election, election_data) ⇒ Object
Methods for Votings Space <-> Elections Component interaction
148 149 150 151 152 153 154 |
# File 'app/models/decidim/votings/voting.rb', line 148 def complete_election_data(election, election_data) election_data[:polling_stations] = polling_stations.map(&:slug) election_data[:ballot_styles] = ballot_styles.map do |ballot_style| questions = ballot_style.questions_for(election) [ballot_style.slug, questions.map(&:slug)] if questions.any? end.compact.to_h end |
#cta_button_text_key ⇒ Object
110 111 112 113 114 |
# File 'app/models/decidim/votings/voting.rb', line 110 def return :vote if published? && active? :more_info end |
#elections ⇒ Object
138 139 140 |
# File 'app/models/decidim/votings/voting.rb', line 138 def elections Decidim::Elections::Election.where(component: components) end |
#finished? ⇒ Boolean
73 74 75 |
# File 'app/models/decidim/votings/voting.rb', line 73 def finished? end_time < Time.now.utc end |
#has_ballot_styles? ⇒ Boolean
134 135 136 |
# File 'app/models/decidim/votings/voting.rb', line 134 def has_ballot_styles? ballot_styles.exists? end |
#period_status ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'app/models/decidim/votings/voting.rb', line 77 def period_status if finished? :finished elsif active? :ongoing else :upcoming end end |
#polling_stations_with_missing_officers? ⇒ Boolean
124 125 126 |
# File 'app/models/decidim/votings/voting.rb', line 124 def polling_stations_with_missing_officers? !online_voting? && polling_stations.any?(&:missing_officers?) end |
#published_elections ⇒ Object
142 143 144 |
# File 'app/models/decidim/votings/voting.rb', line 142 def published_elections Decidim::Elections::Election.where(component: components.published).published end |
#scopes_enabled ⇒ Object
120 121 122 |
# File 'app/models/decidim/votings/voting.rb', line 120 def scopes_enabled true end |
#to_param ⇒ Object
106 107 108 |
# File 'app/models/decidim/votings/voting.rb', line 106 def to_param slug end |
#upcoming? ⇒ Boolean
65 66 67 |
# File 'app/models/decidim/votings/voting.rb', line 65 def upcoming? start_time > Time.now.utc end |
#vote_flow_for(election) ⇒ Object
156 157 158 |
# File 'app/models/decidim/votings/voting.rb', line 156 def vote_flow_for(election) Decidim::Votings::CensusVoteFlow.new(election) end |