Class: Decidim::Budgets::Project

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

Overview

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

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 Followable

#followers

Class Method Details

.log_presenter_class_for(_log) ⇒ Object


47
48
49
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 47

def self.log_presenter_class_for(_log)
  Decidim::Budgets::AdminLog::ProjectPresenter
end

.ordered_ids(ids) ⇒ Object


39
40
41
42
43
44
45
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 39

def self.ordered_ids(ids)
  # Make sure each ID in the matching text has a "," character as their
  # delimiter. Otherwise e.g. ID 2 would match ID "26" in the original
  # array. This is why we search for match ",2," instead to get the actual
  # position for ID 2.
  order(Arel.sql("position(concat(',', id::text, ',') in ',#{ids.join(",")},')"))
end

Instance Method Details

#accepts_new_comments?Boolean

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

Returns:

  • (Boolean)

65
66
67
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 65

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

#allow_resource_permissions?Boolean

Public: Overrides the `allow_resource_permissions?` Resourceable concern method.

Returns:

  • (Boolean)

85
86
87
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 85

def allow_resource_permissions?
  component.settings.resources_permissions_enabled
end

#attachment_contextObject

Public: Returns the attachment context for this record.


102
103
104
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 102

def attachment_context
  :admin
end

#commentable?Boolean

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

Returns:

  • (Boolean)

60
61
62
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 60

def commentable?
  component.settings.comments_enabled?
end

#comments_have_votes?Boolean

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

Returns:

  • (Boolean)

70
71
72
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 70

def comments_have_votes?
  true
end

#confirmed_orders_countObject

Public: Returns the number of times an specific project have been checked out.


80
81
82
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 80

def confirmed_orders_count
  orders.finished.count
end

#polymorphic_resource_path(url_params) ⇒ Object


51
52
53
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 51

def polymorphic_resource_path(url_params)
  ::Decidim::ResourceLocatorPresenter.new([budget, self]).path(url_params)
end

#polymorphic_resource_url(url_params) ⇒ Object


55
56
57
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 55

def polymorphic_resource_url(url_params)
  ::Decidim::ResourceLocatorPresenter.new([budget, self]).url(url_params)
end

#selected?Boolean

Public: Checks if the project has been selected or not.

Returns Boolean.

Returns:

  • (Boolean)

97
98
99
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 97

def selected?
  selected_at.present?
end

#user_allowed_to_comment?(user) ⇒ Boolean

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

Returns:

  • (Boolean)

90
91
92
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 90

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

#users_to_notify_on_comment_createdObject

Public: Overrides the `users_to_notify_on_comment_created` Commentable concern method.


75
76
77
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 75

def users_to_notify_on_comment_created
  followers
end