Class: Decidim::Sortitions::Sortition

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

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.

Returns:

  • (Boolean)


59
60
61
# File 'app/models/decidim/sortitions/sortition.rb', line 59

def accepts_new_comments?
  commentable?
end

#cancelled?Boolean

Returns:

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

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


69
70
71
# File 'app/models/decidim/sortitions/sortition.rb', line 69

def comments_have_votes?
  true
end

#proposalsObject



33
34
35
# File 'app/models/decidim/sortitions/sortition.rb', line 33

def proposals
  Decidim::Proposals::Proposal.where(id: selected_proposals)
end

#seedObject



45
46
47
# File 'app/models/decidim/sortitions/sortition.rb', line 45

def seed
  request_timestamp.to_i * dice
end

#similar_countObject



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