Class: Decidim::Votings::Voting

Inherits:
ApplicationRecord
  • Object
show all
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

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

Returns:

  • (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_contextObject



116
117
118
# File 'app/models/decidim/votings/voting.rb', line 116

def attachment_context
  :admin
end

#available_polling_officersObject



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_keyObject



110
111
112
113
114
# File 'app/models/decidim/votings/voting.rb', line 110

def cta_button_text_key
  return :vote if published? && active?

  :more_info
end

#electionsObject



138
139
140
# File 'app/models/decidim/votings/voting.rb', line 138

def elections
  Decidim::Elections::Election.where(component: components)
end

#finished?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


134
135
136
# File 'app/models/decidim/votings/voting.rb', line 134

def has_ballot_styles?
  ballot_styles.exists?
end

#period_statusObject



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

Returns:

  • (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_electionsObject



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_enabledObject



120
121
122
# File 'app/models/decidim/votings/voting.rb', line 120

def scopes_enabled
  true
end

#to_paramObject



106
107
108
# File 'app/models/decidim/votings/voting.rb', line 106

def to_param
  slug
end

#upcoming?Boolean

Returns:

  • (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