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 Followable

#followers

Class Method Details

.log_presenter_class_for(_log) ⇒ Object


58
59
60
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 58

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

.ordered_ids(ids) ⇒ Object


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

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


127
128
129
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 127

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)

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

def allow_resource_permissions?
  component.settings.resources_permissions_enabled
end

#attachment_contextObject

Public: Returns the attachment context for this record.


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

def attachment_context
  :admin
end

#comments_have_votes?Boolean

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

Returns:

  • (Boolean)

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

def comments_have_votes?
  true
end

#confirmed_orders_countObject

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


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

def confirmed_orders_count
  orders.finished.count
end

#polymorphic_resource_path(url_params) ⇒ Object


62
63
64
# File 'decidim-budgets/app/models/decidim/budgets/project.rb', line 62

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

#polymorphic_resource_url(url_params) ⇒ Object


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

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)

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

def selected?
  selected_at.present?
end

#users_to_notify_on_comment_createdObject

Public: Overrides the `users_to_notify_on_comment_created` Commentable concern method.


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

def users_to_notify_on_comment_created
  followers
end