Class: Decidim::Accountability::Result

Inherits:
ApplicationRecord show all
Includes:
Comments::Commentable, DataPortability, HasAttachmentCollections, HasAttachments, HasCategory, HasComponent, HasReference, Loggable, Randomable, Resourceable, ScopableResource, Searchable, Traceable, TranslatableResource
Defined in:
decidim-accountability/app/models/decidim/accountability/result.rb

Overview

The data store for a Result in the Decidim::Accountability component. It stores a title, description and any other useful information to render a custom result.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Searchable

searchable_resources, searchable_resources_of_type_comment, searchable_resources_of_type_component, searchable_resources_of_type_participant, searchable_resources_of_type_participatory_space

Methods included from HasAttachments

#attachment_context

Class Method Details

.log_presenter_class_for(_log) ⇒ Object


47
48
49
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 47

def self.log_presenter_class_for(_log)
  Decidim::Accountability::AdminLog::ResultPresenter
end

Instance Method Details

#accepts_new_comments?Boolean

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

Returns:

  • (Boolean)

75
76
77
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 75

def accepts_new_comments?
  commentable? && !component.current_settings.comments_blocked
end

#commentable?Boolean

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

Returns:

  • (Boolean)

70
71
72
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 70

def commentable?
  component.settings.comments_enabled?
end

#comments_have_alignment?Boolean

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

Returns:

  • (Boolean)

80
81
82
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 80

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

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

Returns:

  • (Boolean)

85
86
87
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 85

def comments_have_votes?
  true
end

#update_parent_progressObject


51
52
53
54
55
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 51

def update_parent_progress
  return if parent.blank?

  parent.update_progress!
end

#update_progress!Object

Public: There are two ways to update parent's progress:

- using weights, in which case each progress is multiplied by the weigth and them summed
- not using weights, and using the average of progress of each children

60
61
62
63
64
65
66
67
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 60

def update_progress!
  self.progress = if children_use_weighted_progress?
                    children.sum { |result| (result.progress.presence || 0) * (result.weight.presence || 1) }
                  else
                    children.average(:progress)
                  end
  save!
end

#user_allowed_to_comment?(user) ⇒ Boolean

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

Returns:

  • (Boolean)

90
91
92
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 90

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