Class: Decidim::Plans::Plan
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Plans::Plan
- Includes:
- Coauthorable, Comments::Commentable, Followable, HasAttachments, HasCategory, HasComponent, Loggable, Traceable, Reportable, Resourceable, ScopableComponent, Searchable
- Defined in:
- app/models/decidim/plans/plan.rb
Overview
A plan is similar to a proposal but allows the users to fill in multiple custom fields that the admin users define for each plans component. The fields are the plan sections and the contents are in plan contents.
Class Method Summary collapse
- .data_portability_images(user) ⇒ Object
- .export_serializer ⇒ Object
- .log_presenter_class_for(_log) ⇒ Object
- .order_randomly(seed) ⇒ Object
-
.user_collection(author) ⇒ Object
Returns a collection scoped by an author.
Instance Method Summary collapse
-
#accepted? ⇒ Boolean
Public: Checks if the organization has accepted a plan.
- #accepts_new_comments? ⇒ Boolean
-
#answered? ⇒ Boolean
Public: Checks if the organization has given an answer for the plan.
-
#closed? ⇒ Boolean
Public: Checks if the plan has been closed or not.
- #commentable? ⇒ Boolean
- #comments_have_alignment? ⇒ Boolean
- #comments_have_votes? ⇒ Boolean
-
#draft? ⇒ Boolean
Public: Whether the plan is a draft or not.
-
#editable_by?(user) ⇒ Boolean
Checks whether the user can edit the given plan.
-
#evaluating? ⇒ Boolean
Public: Checks if the organization has marked the plan as evaluating it.
-
#open? ⇒ Boolean
Public: Checks if the plan is open for edits.
-
#published? ⇒ Boolean
Public: Checks if the plan has been published or not.
-
#rejected? ⇒ Boolean
Public: Checks if the organization has rejected a plan.
-
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
- #sections ⇒ Object
- #users_to_notify_on_comment_created ⇒ Object
-
#waiting_for_evaluation? ⇒ Boolean
Public: Checks if the plan has been closed AND not yet answered.
-
#withdrawable_by?(user) ⇒ Boolean
Checks whether the user can withdraw the given plan.
-
#withdrawn? ⇒ Boolean
Public: Checks if the author has withdrawn the plan.
-
#within_edit_time_limit? ⇒ Boolean
Checks whether the plan is inside the time window to be editable or not once published.
Methods included from Traceable
Class Method Details
.data_portability_images(user) ⇒ Object
216 217 218 |
# File 'app/models/decidim/plans/plan.rb', line 216 def self.data_portability_images(user) user_collection(user).map { |p| p..collect(&:file) } end |
.export_serializer ⇒ Object
212 213 214 |
# File 'app/models/decidim/plans/plan.rb', line 212 def self.export_serializer Decidim::Plans::PlanSerializer end |
.log_presenter_class_for(_log) ⇒ Object
77 78 79 |
# File 'app/models/decidim/plans/plan.rb', line 77 def self.log_presenter_class_for(_log) Decidim::Plans::AdminLog::PlanPresenter end |
.order_randomly(seed) ⇒ Object
70 71 72 73 74 75 |
# File 'app/models/decidim/plans/plan.rb', line 70 def self.order_randomly(seed) transaction do connection.execute("SELECT setseed(#{connection.quote(seed)})") order(Arel.sql("RANDOM()")).load end end |
.user_collection(author) ⇒ Object
Returns a collection scoped by an author. Overrides this method in DataPortability to support Coauthorable.
83 84 85 86 87 88 89 |
# File 'app/models/decidim/plans/plan.rb', line 83 def self.user_collection() return unless .is_a?(Decidim::User) joins(:coauthorships) .where("decidim_coauthorships.coauthorable_type = ?", name) .where("decidim_coauthorships.decidim_author_id = ? AND decidim_coauthorships.decidim_author_type = ? ", .id, .class.base_class.name) end |
Instance Method Details
#accepted? ⇒ Boolean
Public: Checks if the organization has accepted a plan.
Returns Boolean.
130 131 132 |
# File 'app/models/decidim/plans/plan.rb', line 130 def accepted? answered? && state == "accepted" end |
#accepts_new_comments? ⇒ Boolean
183 184 185 |
# File 'app/models/decidim/plans/plan.rb', line 183 def accepts_new_comments? commentable? && !component.current_settings.comments_blocked end |
#answered? ⇒ Boolean
Public: Checks if the organization has given an answer for the plan.
Returns Boolean.
123 124 125 |
# File 'app/models/decidim/plans/plan.rb', line 123 def answered? answered_at.present? && state.present? end |
#closed? ⇒ Boolean
Public: Checks if the plan has been closed or not.
Returns Boolean.
108 109 110 |
# File 'app/models/decidim/plans/plan.rb', line 108 def closed? closed_at.present? end |
#commentable? ⇒ Boolean
179 180 181 |
# File 'app/models/decidim/plans/plan.rb', line 179 def commentable? component.settings.comments_enabled? end |
#comments_have_alignment? ⇒ Boolean
187 188 189 |
# File 'app/models/decidim/plans/plan.rb', line 187 def comments_have_alignment? true end |
#comments_have_votes? ⇒ Boolean
191 192 193 |
# File 'app/models/decidim/plans/plan.rb', line 191 def comments_have_votes? true end |
#draft? ⇒ Boolean
Public: Whether the plan is a draft or not.
175 176 177 |
# File 'app/models/decidim/plans/plan.rb', line 175 def draft? published_at.nil? end |
#editable_by?(user) ⇒ Boolean
Checks whether the user can edit the given plan.
user - the user to check for authorship
163 164 165 |
# File 'app/models/decidim/plans/plan.rb', line 163 def editable_by?(user) !answered? && !copied_from_other_component? && (user) end |
#evaluating? ⇒ Boolean
Public: Checks if the organization has marked the plan as evaluating it.
Returns Boolean.
144 145 146 |
# File 'app/models/decidim/plans/plan.rb', line 144 def evaluating? answered? && state == "evaluating" end |
#open? ⇒ Boolean
Public: Checks if the plan is open for edits.
Returns Boolean.
94 95 96 |
# File 'app/models/decidim/plans/plan.rb', line 94 def open? state == "open" end |
#published? ⇒ Boolean
Public: Checks if the plan has been published or not.
Returns Boolean.
101 102 103 |
# File 'app/models/decidim/plans/plan.rb', line 101 def published? published_at.present? end |
#rejected? ⇒ Boolean
Public: Checks if the organization has rejected a plan.
Returns Boolean.
137 138 139 |
# File 'app/models/decidim/plans/plan.rb', line 137 def rejected? answered? && state == "rejected" end |
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
156 157 158 |
# File 'app/models/decidim/plans/plan.rb', line 156 def reported_content_url ResourceLocatorPresenter.new(self).url end |
#sections ⇒ Object
66 67 68 |
# File 'app/models/decidim/plans/plan.rb', line 66 def sections Section.where(component: component).order(:position) end |
#users_to_notify_on_comment_created ⇒ Object
195 196 197 |
# File 'app/models/decidim/plans/plan.rb', line 195 def users_to_notify_on_comment_created followers end |
#waiting_for_evaluation? ⇒ Boolean
Public: Checks if the plan has been closed AND not yet answered. This is
interpreted as the plan waiting to be evaluated.
Returns Boolean.
116 117 118 |
# File 'app/models/decidim/plans/plan.rb', line 116 def waiting_for_evaluation? closed? && !answered? end |
#withdrawable_by?(user) ⇒ Boolean
Checks whether the user can withdraw the given plan.
user - the user to check for withdrawability.
170 171 172 |
# File 'app/models/decidim/plans/plan.rb', line 170 def withdrawable_by?(user) user && !withdrawn? && == user && !copied_from_other_component? end |
#withdrawn? ⇒ Boolean
Public: Checks if the author has withdrawn the plan.
Returns Boolean.
151 152 153 |
# File 'app/models/decidim/plans/plan.rb', line 151 def withdrawn? state == "withdrawn" end |
#within_edit_time_limit? ⇒ Boolean
Checks whether the plan is inside the time window to be editable or not once published.
221 222 223 |
# File 'app/models/decidim/plans/plan.rb', line 221 def within_edit_time_limit? true end |