Class: Decidim::Sortitions::Sortition

Inherits:
ApplicationRecord show all
Includes:
Authorable, Comments::Commentable, HasCategory, HasComponent, HasReference, Loggable, Randomable, Resourceable, Traceable, TranslatableResource
Defined in:
decidim-sortitions/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

.log_presenter_class_for(_log) ⇒ Object


37
38
39
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 37

def self.log_presenter_class_for(_log)
  Decidim::Sortitions::AdminLog::SortitionPresenter
end

Instance Method Details

#accepts_new_comments?Boolean

Public: Overrides the `accepts_new_comments?` Commentable concern method.

Returns:

  • (Boolean)

67
68
69
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 67

def accepts_new_comments?
  commentable?
end

#cancelled?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 57

def cancelled?
  cancelled_on.present?
end

#commentable?Boolean

Public: Overrides the `commentable?` Commentable concern method.

Returns:

  • (Boolean)

62
63
64
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 62

def commentable?
  component.settings.comments_enabled?
end

#comments_have_alignment?Boolean

Public: Overrides the `comments_have_alignment?` Commentable concern method.

Returns:

  • (Boolean)

72
73
74
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 72

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

Public: Overrides the `comments_have_votes?` Commentable concern method.

Returns:

  • (Boolean)

77
78
79
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 77

def comments_have_votes?
  true
end

#proposalsObject


41
42
43
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 41

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

#seedObject


53
54
55
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 53

def seed
  request_timestamp.to_i * dice
end

#similar_countObject


45
46
47
48
49
50
51
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 45

def similar_count
  Sortition.where(component: component)
           .where(decidim_proposals_component: decidim_proposals_component)
           .categorized_as(category&.id)
           .where(target_items: target_items)
           .count
end

#user_allowed_to_comment?(user) ⇒ Boolean

Public: Whether the object can have new comments or not.

Returns:

  • (Boolean)

82
83
84
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 82

def user_allowed_to_comment?(user)
  can_participate_in_space?(user)
end