Class: Decidim::Budgets::Project

Inherits:
ApplicationRecord show all
Includes:
Comments::CommentableWithComponent, FilterableResource, 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


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

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

.ordered_ids(ids) ⇒ Object


47
48
49
50
51
52
53
54
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 47

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.
  concat_ids = connection.quote(",#{ids.join(",")},")
  order(Arel.sql("position(concat(',', id::text, ',') in #{concat_ids})"))
end

.ransackable_scopes(_auth_object = nil) ⇒ Object


125
126
127
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 125

def self.ransackable_scopes(_auth_object = nil)
  [:with_any_status, :with_any_scope, :with_any_category]
end

Instance Method Details

#allow_resource_permissions?Boolean

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

Returns:

  • (Boolean)

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

def allow_resource_permissions?
  component.settings.resources_permissions_enabled
end

#attachment_contextObject

Public: Returns the attachment context for this record.


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

def attachment_context
  :admin
end

#comments_have_votes?Boolean

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

Returns:

  • (Boolean)

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

def comments_have_votes?
  true
end

#confirmed_orders_countObject

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


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

def confirmed_orders_count
  orders.finished.count
end

#polymorphic_resource_path(url_params) ⇒ Object


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

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

#polymorphic_resource_url(url_params) ⇒ Object


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

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)

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

def selected?
  selected_at.present?
end

#users_to_notify_on_comment_createdObject

Public: Overrides the `users_to_notify_on_comment_created` Commentable concern method.


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

def users_to_notify_on_comment_created
  followers
end