Class: Decidim::Sortitions::Sortition
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Sortitions::Sortition
- Includes:
- Authorable, Comments::Commentable, HasCategory, HasFeature, HasReference, Resourceable
- Defined in:
- app/models/decidim/sortitions/sortition.rb
Overview
Model that encapsulates the parameters of a sortion
Class Method Summary collapse
Instance Method Summary collapse
-
#accepts_new_comments? ⇒ Boolean
Public: Overrides the ‘accepts_new_comments?` Commentable concern method.
- #cancelled? ⇒ Boolean
-
#commentable? ⇒ Boolean
Public: Overrides the ‘commentable?` Commentable concern method.
-
#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.
- #proposals ⇒ Object
- #seed ⇒ Object
- #similar_count ⇒ Object
Class Method Details
.order_randomly(seed) ⇒ Object
73 74 75 76 77 78 |
# File 'app/models/decidim/sortitions/sortition.rb', line 73 def self.order_randomly(seed) transaction do connection.execute("SELECT setseed(#{connection.quote(seed)})") order("RANDOM()").load end end |
Instance Method Details
#accepts_new_comments? ⇒ Boolean
Public: Overrides the ‘accepts_new_comments?` Commentable concern method.
59 60 61 |
# File 'app/models/decidim/sortitions/sortition.rb', line 59 def accepts_new_comments? commentable? end |
#cancelled? ⇒ Boolean
49 50 51 |
# File 'app/models/decidim/sortitions/sortition.rb', line 49 def cancelled? cancelled_on.present? end |
#commentable? ⇒ Boolean
Public: Overrides the ‘commentable?` Commentable concern method.
54 55 56 |
# File 'app/models/decidim/sortitions/sortition.rb', line 54 def commentable? feature.settings.comments_enabled? end |
#comments_have_alignment? ⇒ Boolean
Public: Overrides the ‘comments_have_alignment?` Commentable concern method.
64 65 66 |
# File 'app/models/decidim/sortitions/sortition.rb', line 64 def comments_have_alignment? true end |
#comments_have_votes? ⇒ Boolean
Public: Overrides the ‘comments_have_votes?` Commentable concern method.
69 70 71 |
# File 'app/models/decidim/sortitions/sortition.rb', line 69 def comments_have_votes? true end |
#proposals ⇒ Object
33 34 35 |
# File 'app/models/decidim/sortitions/sortition.rb', line 33 def proposals Decidim::Proposals::Proposal.where(id: selected_proposals) end |
#seed ⇒ Object
45 46 47 |
# File 'app/models/decidim/sortitions/sortition.rb', line 45 def seed .to_i * dice end |
#similar_count ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/models/decidim/sortitions/sortition.rb', line 37 def similar_count Sortition.where(feature: feature) .where(decidim_proposals_feature: decidim_proposals_feature) .categorized_as(category&.id) .where(target_items: target_items) .count end |