Class: Decidim::Elections::Election

Inherits:
ApplicationRecord show all
Includes:
FilterableResource, Forms::HasQuestionnaire, HasAttachmentCollections, HasAttachments, HasComponent, Loggable, Publicable, Resourceable, Traceable, TranslatableResource
Defined in:
decidim-elections/app/models/decidim/elections/election.rb

Overview

The data store for an Election in the Decidim::Elections component. It stores a title, description and any other useful information to perform an election.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Publicable

#publish!, #published?, #unpublish!

Methods included from HasAttachments

#attachment_context

Class Method Details

.log_presenter_class_for(_log) ⇒ Object


49
50
51
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 49

def self.log_presenter_class_for(_log)
  Decidim::Elections::AdminLog::ElectionPresenter
end

.ransackable_scopes(_auth_object = nil) ⇒ Object


149
150
151
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 149

def self.ransackable_scopes(_auth_object = nil)
  [:with_any_date]
end

Instance Method Details

#allow_resource_permissions?Boolean

Public: Overrides the Resourceable concern method to allow setting permissions at resource level

Returns:

  • (Boolean)

141
142
143
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 141

def allow_resource_permissions?
  true
end

#blocked?Boolean

Public: Checks if the election has a blocked_at value

Returns a boolean.

Returns:

  • (Boolean)

136
137
138
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 136

def blocked?
  blocked_at.present?
end

#finished?Boolean

Public: Checks if the election finished

Returns a boolean.

Returns:

  • (Boolean)

63
64
65
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 63

def finished?
  end_time < Time.current
end

#maximum_hours_before_start?Boolean

Public: Checks if the election start_time is maximum some hours before than the present time

Returns a boolean.

Returns:

  • (Boolean)

84
85
86
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 84

def maximum_hours_before_start?
  start_time < (Time.zone.at(Decidim::Elections.start_vote_maximum_hours_before_start.hours.from_now))
end

#minimum_answers?Boolean

Public: Checks if the number of answers are minimum 2 for each question

Returns a boolean.

Returns:

  • (Boolean)

91
92
93
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 91

def minimum_answers?
  questions.all? { |question| question.answers.size > 1 }
end

#minimum_hours_before_start?Boolean

Public: Checks if the election start_time is minimum some hours later than the present time

Returns a boolean.

Returns:

  • (Boolean)

77
78
79
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 77

def minimum_hours_before_start?
  start_time > (Time.zone.at(Decidim::Elections.setup_minimum_hours_before_start.hours.from_now))
end

#ongoing?Boolean

Public: Checks if the election ongoing now

Returns a boolean.

Returns:

  • (Boolean)

70
71
72
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 70

def ongoing?
  started? && !finished?
end

#results?Boolean

Public: Checks if the election results are present

Returns a boolean.

Returns:

  • (Boolean)

105
106
107
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 105

def results?
  bb_tally_ended? || results_published?
end

#results_published?Boolean

Public: Checks if the election results are published and election finished

Returns a boolean.

Returns:

  • (Boolean)

98
99
100
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 98

def results_published?
  bb_results_published?
end

#started?Boolean

Public: Checks if the election started

Returns a boolean.

Returns:

  • (Boolean)

56
57
58
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 56

def started?
  start_time <= Time.current
end

#trustee_action_required?Boolean

Returns:

  • (Boolean)

129
130
131
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 129

def trustee_action_required?
  bb_key_ceremony? || bb_tally_started?
end

#valid_questions?Boolean

Public: Checks if the election questions are valid

Returns a boolean.

Returns:

  • (Boolean)

112
113
114
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 112

def valid_questions?
  questions.all?(&:valid_max_selection?)
end

#voting_period_statusObject

Public: Gets the voting period status of the election

Returns one of these symbols: upcoming, ongoing or finished


119
120
121
122
123
124
125
126
127
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 119

def voting_period_status
  if finished?
    :finished
  elsif started?
    :ongoing
  else
    :upcoming
  end
end