Class: Decidim::Consultations::Question
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Consultations::Question
- Includes:
- Decidim::Comments::Commentable, Followable, HasAttachmentCollections, HasAttachments, HasResourcePermission, HasUploadValidations, Loggable, Participable, ParticipatorySpaceResourceable, Publicable, Randomable, ScopableParticipatorySpace, Traceable, TranslatableResource
- Defined in:
- app/models/decidim/consultations/question.rb
Overview
The data store for Consultation questions in the Decidim::Consultations component.
Class Method Summary collapse
Instance Method Summary collapse
-
#allow_resource_permissions? ⇒ Boolean
Public: Overrides the ‘allow_resource_permissions?` Resourceable concern method.
- #attachment_context ⇒ Object
- #banner_image_url ⇒ Object
-
#can_be_unvoted_by?(user) ⇒ Boolean
Public: Checks whether the given user can unvote the question or note.
-
#can_be_voted_by?(user) ⇒ Boolean
Public: Checks whether the given user can vote the question or note.
-
#comments_have_alignment? ⇒ Boolean
Public: Overrides the ‘comments_have_alignment?` Commentable concern method.
-
#comments_have_votes? ⇒ Boolean
Public: Overrides the ‘comments_have_votes?` Commentable concern method.
- #grouped? ⇒ Boolean
-
#grouped_responses ⇒ Object
matrix of responses by group (sorted by configuration).
- #hashtag ⇒ Object
-
#module_name ⇒ Object
Overrides module name from participable concern.
- #most_voted_response ⇒ Object
- #mounted_admin_engine ⇒ Object
- #mounted_engine ⇒ Object
-
#multiple? ⇒ Boolean
Multiple answers allowed?.
-
#publishable_results? ⇒ Boolean
if results can be shown to admins.
- #resource_description ⇒ Object
- #scopes_enabled ⇒ Object
- #scopes_enabled? ⇒ Boolean
-
#sorted_responses ⇒ Object
Sorted responses by date so admins have a way to predict it.
-
#sorted_results ⇒ Object
Sorted results for the given question.
- #to_param ⇒ Object
-
#total_participants ⇒ Object
Total number of users voting.
-
#total_votes ⇒ Object
Total number of votes, on multiple votes questions does not match users voting.
-
#voted_by?(user) ⇒ Boolean
Public: Check if the user has voted the question.
Class Method Details
.participatory_space_manifest ⇒ Object
191 192 193 |
# File 'app/models/decidim/consultations/question.rb', line 191 def self.participatory_space_manifest Decidim.find_participatory_space_manifest(Decidim::Consultation.name.demodulize.underscore.pluralize) end |
Instance Method Details
#allow_resource_permissions? ⇒ Boolean
Public: Overrides the ‘allow_resource_permissions?` Resourceable concern method.
200 201 202 |
# File 'app/models/decidim/consultations/question.rb', line 200 def true end |
#attachment_context ⇒ Object
204 205 206 |
# File 'app/models/decidim/consultations/question.rb', line 204 def :admin end |
#banner_image_url ⇒ Object
134 135 136 |
# File 'app/models/decidim/consultations/question.rb', line 134 def .present? ? .url : consultation..url end |
#can_be_unvoted_by?(user) ⇒ Boolean
Public: Checks whether the given user can unvote the question or note.
Returns a Boolean.
148 149 150 151 152 153 |
# File 'app/models/decidim/consultations/question.rb', line 148 def can_be_unvoted_by?(user) consultation.active? && consultation.published? && published? && voted_by?(user) end |
#can_be_voted_by?(user) ⇒ Boolean
Public: Checks whether the given user can vote the question or note.
Returns a Boolean.
158 159 160 161 162 163 164 |
# File 'app/models/decidim/consultations/question.rb', line 158 def can_be_voted_by?(user) organization.id == user.organization.id && consultation.active? && consultation.published? && published? && !voted_by?(user) end |
#comments_have_alignment? ⇒ Boolean
Public: Overrides the ‘comments_have_alignment?` Commentable concern method.
121 122 123 |
# File 'app/models/decidim/consultations/question.rb', line 121 def comments_have_alignment? true end |
#comments_have_votes? ⇒ Boolean
Public: Overrides the ‘comments_have_votes?` Commentable concern method.
126 127 128 |
# File 'app/models/decidim/consultations/question.rb', line 126 def comments_have_votes? true end |
#grouped? ⇒ Boolean
114 115 116 117 118 |
# File 'app/models/decidim/consultations/question.rb', line 114 def grouped? return false unless multiple? response_groups_count.positive? end |
#grouped_responses ⇒ Object
matrix of responses by group (sorted by configuration)
110 111 112 |
# File 'app/models/decidim/consultations/question.rb', line 110 def grouped_responses @grouped_responses ||= sorted_responses.group_by(&:response_group) end |
#hashtag ⇒ Object
130 131 132 |
# File 'app/models/decidim/consultations/question.rb', line 130 def hashtag attributes["hashtag"].to_s.delete("#") end |
#module_name ⇒ Object
Overrides module name from participable concern
179 180 181 |
# File 'app/models/decidim/consultations/question.rb', line 179 def module_name "Decidim::Consultations" end |
#most_voted_response ⇒ Object
82 83 84 |
# File 'app/models/decidim/consultations/question.rb', line 82 def most_voted_response @most_voted_response ||= responses.order(votes_count: :desc).first end |
#mounted_admin_engine ⇒ Object
187 188 189 |
# File 'app/models/decidim/consultations/question.rb', line 187 def mounted_admin_engine "decidim_admin_consultations" end |
#mounted_engine ⇒ Object
183 184 185 |
# File 'app/models/decidim/consultations/question.rb', line 183 def mounted_engine "decidim_consultations" end |
#multiple? ⇒ Boolean
Multiple answers allowed?
97 98 99 100 101 102 |
# File 'app/models/decidim/consultations/question.rb', line 97 def multiple? return false if external_voting return false if max_votes.blank? max_votes > 1 end |
#publishable_results? ⇒ Boolean
if results can be shown to admins
78 79 80 |
# File 'app/models/decidim/consultations/question.rb', line 78 def publishable_results? consultation.finished? && sorted_results.any? end |
#resource_description ⇒ Object
195 196 197 |
# File 'app/models/decidim/consultations/question.rb', line 195 def resource_description subtitle end |
#scopes_enabled ⇒ Object
170 171 172 |
# File 'app/models/decidim/consultations/question.rb', line 170 def scopes_enabled false end |
#scopes_enabled? ⇒ Boolean
166 167 168 |
# File 'app/models/decidim/consultations/question.rb', line 166 def scopes_enabled? false end |
#sorted_responses ⇒ Object
Sorted responses by date so admins have a way to predict it
105 106 107 |
# File 'app/models/decidim/consultations/question.rb', line 105 def sorted_responses @sorted_responses ||= responses.sort_by(&:created_at) end |
#sorted_results ⇒ Object
Sorted results for the given question.
73 74 75 |
# File 'app/models/decidim/consultations/question.rb', line 73 def sorted_results responses.order(votes_count: :desc) end |
#to_param ⇒ Object
174 175 176 |
# File 'app/models/decidim/consultations/question.rb', line 174 def to_param slug end |
#total_participants ⇒ Object
Total number of users voting
92 93 94 |
# File 'app/models/decidim/consultations/question.rb', line 92 def total_participants @total_participants ||= votes.select(:decidim_author_id).distinct.count end |
#total_votes ⇒ Object
Total number of votes, on multiple votes questions does not match users voting
87 88 89 |
# File 'app/models/decidim/consultations/question.rb', line 87 def total_votes @total_votes ||= responses.sum(&:votes_count) end |
#voted_by?(user) ⇒ Boolean
Public: Check if the user has voted the question.
Returns Boolean.
141 142 143 |
# File 'app/models/decidim/consultations/question.rb', line 141 def voted_by?(user) votes.where(author: user).any? end |