Class: Decidim::Budgets::Project

Inherits:
ApplicationRecord show all
Includes:
Comments::CommentableWithComponent, Followable, HasAttachmentCollections, HasAttachments, HasCategory, HasReference, Loggable, Randomable, Resourceable, ScopableResource, Searchable, Traceable, TranslatableResource
Defined in:
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

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



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

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

.ordered_ids(ids) ⇒ Object



44
45
46
47
48
49
50
# File 'app/models/decidim/budgets/project.rb', line 44

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

#allow_resource_permissions?Boolean

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

Returns:

  • (Boolean)


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

def allow_resource_permissions?
  component.settings.resources_permissions_enabled
end

#attachment_contextObject

Public: Returns the attachment context for this record.



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

def attachment_context
  :admin
end

#comments_have_votes?Boolean

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

Returns:

  • (Boolean)


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

def comments_have_votes?
  true
end

#confirmed_orders_countObject

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



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

def confirmed_orders_count
  orders.finished.count
end

#polymorphic_resource_path(url_params) ⇒ Object



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

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

#polymorphic_resource_url(url_params) ⇒ Object



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

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)


87
88
89
# File 'app/models/decidim/budgets/project.rb', line 87

def selected?
  selected_at.present?
end

#users_to_notify_on_comment_createdObject

Public: Overrides the ‘users_to_notify_on_comment_created` Commentable concern method.



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

def users_to_notify_on_comment_created
  followers
end