Class: Project
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Project
- Extended by:
- CatarseAutoHtml
- Includes:
- ActionView::Helpers::TextHelper, PgSearch
- Defined in:
- app/models/project.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#accepted_terms ⇒ Object
Returns the value of attribute accepted_terms.
Class Method Summary collapse
- .between_created_at(start_at, ends_at) ⇒ Object
- .between_expires_at(start_at, ends_at) ⇒ Object
- .finish_projects! ⇒ Object
- .permalink_on_routes?(permalink) ⇒ Boolean
- .state_names ⇒ Object
Instance Method Summary collapse
- #after_transition_of_any_to_failed_or_successful ⇒ Object
- #after_transition_of_draft_or_rejected_to_deleted ⇒ Object
- #after_transition_of_draft_to_online ⇒ Object
- #after_transition_of_draft_to_rejected ⇒ Object
- #after_transition_of_online_to_failed ⇒ Object
- #after_transition_of_online_to_waiting_funds ⇒ Object
- #after_transition_of_wainting_funds_to_successful ⇒ Object
- #after_transition_of_wainting_funds_to_successful_or_failed ⇒ Object
- #after_transition_of_waiting_funds_to_failed_or_successful ⇒ Object
- #can_go_to_second_chance? ⇒ Boolean
- #decorator ⇒ Object
- #download_video_thumbnail ⇒ Object
- #expired? ⇒ Boolean
- #expires_at ⇒ Object
- #finished? ⇒ Boolean
- #in_time? ⇒ Boolean
- #in_time_to_wait? ⇒ Boolean
- #new_draft_project_notification_type ⇒ Object
- #new_draft_recipient ⇒ Object
- #new_project_received_notification_type ⇒ Object
- #pending_backers_reached_the_goal? ⇒ Boolean
- #permalink_cant_be_route ⇒ Object
- #pledged ⇒ Object
- #progress ⇒ Object
- #reached_goal? ⇒ Boolean
- #remaining_text ⇒ Object
- #selected_rewards ⇒ Object
- #subscribed_users ⇒ Object
- #time_to_go ⇒ Object
- #total_backers ⇒ Object
- #total_payment_service_fee ⇒ Object
- #update_video_embed_url ⇒ Object
- #video ⇒ Object
Methods included from CatarseAutoHtml
Instance Attribute Details
#accepted_terms ⇒ Object
Returns the value of attribute accepted_terms.
83 84 85 |
# File 'app/models/project.rb', line 83 def accepted_terms @accepted_terms end |
Class Method Details
.between_created_at(start_at, ends_at) ⇒ Object
96 97 98 99 |
# File 'app/models/project.rb', line 96 def self.between_created_at(start_at, ends_at) return scoped unless start_at.present? && ends_at.present? where("created_at between to_date(?, 'dd/mm/yyyy') and to_date(?, 'dd/mm/yyyy')", start_at, ends_at) end |
.between_expires_at(start_at, ends_at) ⇒ Object
101 102 103 104 |
# File 'app/models/project.rb', line 101 def self.between_expires_at(start_at, ends_at) return scoped unless start_at.present? && ends_at.present? where("projects.expires_at between to_date(?, 'dd/mm/yyyy') and to_date(?, 'dd/mm/yyyy')", start_at, ends_at) end |
.finish_projects! ⇒ Object
106 107 108 109 110 111 |
# File 'app/models/project.rb', line 106 def self.finish_projects! to_finish.each do |resource| Rails.logger.info "[FINISHING PROJECT #{resource.id}] #{resource.name}" resource.finish end end |
.permalink_on_routes?(permalink) ⇒ Boolean
215 216 217 |
# File 'app/models/project.rb', line 215 def self.permalink_on_routes?(permalink) permalink && self.get_routes.include?(permalink.downcase) end |
.state_names ⇒ Object
113 114 115 116 117 |
# File 'app/models/project.rb', line 113 def self.state_names self.state_machine.states.map do |state| state.name if state.name != :deleted end.compact! end |
Instance Method Details
#after_transition_of_any_to_failed_or_successful ⇒ Object
290 291 292 |
# File 'app/models/project.rb', line 290 def after_transition_of_any_to_failed_or_successful notify_observers :sync_with_mailchimp end |
#after_transition_of_draft_or_rejected_to_deleted ⇒ Object
278 279 280 |
# File 'app/models/project.rb', line 278 def after_transition_of_draft_or_rejected_to_deleted update_attributes({ permalink: "deleted_project_#{id}"}) end |
#after_transition_of_draft_to_online ⇒ Object
310 311 312 313 |
# File 'app/models/project.rb', line 310 def after_transition_of_draft_to_online update_attributes({ online_date: DateTime.now }) notify_observers :notify_owner_that_project_is_online end |
#after_transition_of_draft_to_rejected ⇒ Object
302 303 304 |
# File 'app/models/project.rb', line 302 def after_transition_of_draft_to_rejected notify_observers :notify_owner_that_project_is_rejected end |
#after_transition_of_online_to_failed ⇒ Object
294 295 296 |
# File 'app/models/project.rb', line 294 def after_transition_of_online_to_failed notify_observers :notify_users end |
#after_transition_of_online_to_waiting_funds ⇒ Object
282 283 284 |
# File 'app/models/project.rb', line 282 def after_transition_of_online_to_waiting_funds notify_observers :notify_owner_that_project_is_waiting_funds end |
#after_transition_of_wainting_funds_to_successful ⇒ Object
298 299 300 |
# File 'app/models/project.rb', line 298 def after_transition_of_wainting_funds_to_successful notify_observers :notify_owner_that_project_is_successful end |
#after_transition_of_wainting_funds_to_successful_or_failed ⇒ Object
306 307 308 |
# File 'app/models/project.rb', line 306 def after_transition_of_wainting_funds_to_successful_or_failed notify_observers :notify_users end |
#after_transition_of_waiting_funds_to_failed_or_successful ⇒ Object
286 287 288 |
# File 'app/models/project.rb', line 286 def after_transition_of_waiting_funds_to_failed_or_successful notify_observers :notify_admin_that_project_reached_deadline end |
#can_go_to_second_chance? ⇒ Boolean
207 208 209 |
# File 'app/models/project.rb', line 207 def can_go_to_second_chance? ((pledged + backers.in_time_to_confirm.sum(&:value)) >= (goal*0.3.to_f)) && (4.weekdays_from(expires_at) >= DateTime.now) end |
#decorator ⇒ Object
123 124 125 |
# File 'app/models/project.rb', line 123 def decorator @decorator ||= ProjectDecorator.new(self) end |
#download_video_thumbnail ⇒ Object
195 196 197 198 199 200 201 |
# File 'app/models/project.rb', line 195 def download_video_thumbnail self.video_thumbnail = open(self.video.thumbnail_large) if self.video_url.present? && self.video rescue OpenURI::HTTPError => e Rails.logger.info "-----> #{e.inspect}" rescue TypeError => e Rails.logger.info "-----> #{e.inspect}" end |
#expired? ⇒ Boolean
159 160 161 |
# File 'app/models/project.rb', line 159 def expired? expires_at && expires_at < Time.zone.now end |
#expires_at ⇒ Object
127 128 129 |
# File 'app/models/project.rb', line 127 def expires_at online_date && (online_date + online_days.days).end_of_day end |
#finished? ⇒ Boolean
155 156 157 |
# File 'app/models/project.rb', line 155 def finished? not online? and not draft? and not rejected? end |
#in_time? ⇒ Boolean
167 168 169 |
# File 'app/models/project.rb', line 167 def in_time? !expired? end |
#in_time_to_wait? ⇒ Boolean
163 164 165 |
# File 'app/models/project.rb', line 163 def in_time_to_wait? backers.in_time_to_confirm.count > 0 end |
#new_draft_project_notification_type ⇒ Object
320 321 322 |
# File 'app/models/project.rb', line 320 def new_draft_project_notification_type channels.first ? :new_draft_project_channel : :new_draft_project end |
#new_draft_recipient ⇒ Object
315 316 317 318 |
# File 'app/models/project.rb', line 315 def new_draft_recipient email = (channels.first.email rescue nil) || ::Configuration[:email_projects] User.where(email: email).first end |
#new_project_received_notification_type ⇒ Object
324 325 326 |
# File 'app/models/project.rb', line 324 def new_project_received_notification_type channels.first ? :project_received_channel : :project_received end |
#pending_backers_reached_the_goal? ⇒ Boolean
203 204 205 |
# File 'app/models/project.rb', line 203 def pending_backers_reached_the_goal? (pledged + backers.in_time_to_confirm.sum(&:value)) >= goal end |
#permalink_cant_be_route ⇒ Object
211 212 213 |
# File 'app/models/project.rb', line 211 def permalink_cant_be_route errors.add(:permalink, I18n.t("activerecord.errors.models.project.attributes.permalink.invalid")) if Project.permalink_on_routes?(permalink) end |
#pledged ⇒ Object
135 136 137 |
# File 'app/models/project.rb', line 135 def pledged project_total ? project_total.pledged : 0.0 end |
#progress ⇒ Object
171 172 173 174 175 |
# File 'app/models/project.rb', line 171 def progress return 0 if goal == 0.0 && pledged == 0.0 return 100 if goal == 0.0 && pledged > 0.0 ((pledged / goal * 100).abs).round(pledged.to_i.size).to_i end |
#reached_goal? ⇒ Boolean
151 152 153 |
# File 'app/models/project.rb', line 151 def reached_goal? pledged >= goal end |
#remaining_text ⇒ Object
187 188 189 |
# File 'app/models/project.rb', line 187 def remaining_text pluralize_without_number(time_to_go[:time], I18n.t('remaining_singular'), I18n.t('remaining_plural')) end |
#selected_rewards ⇒ Object
147 148 149 |
# File 'app/models/project.rb', line 147 def selected_rewards rewards.sort_asc.where(id: backers.confirmed.select('DISTINCT(reward_id)')) end |
#subscribed_users ⇒ Object
119 120 121 |
# File 'app/models/project.rb', line 119 def subscribed_users User.subscribed_to_updates.subscribed_to_project(self.id) end |
#time_to_go ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'app/models/project.rb', line 177 def time_to_go ['day', 'hour', 'minute', 'second'].each do |unit| if expires_at.to_i >= 1.send(unit).from_now.to_i time = ((expires_at - Time.zone.now).abs/1.send(unit)).round return {time: time, unit: pluralize_without_number(time, I18n.t("datetime.prompts.#{unit}").downcase)} end end {time: 0, unit: pluralize_without_number(0, I18n.t('datetime.prompts.second').downcase)} end |
#total_backers ⇒ Object
139 140 141 |
# File 'app/models/project.rb', line 139 def total_backers project_total ? project_total.total_backers : 0 end |
#total_payment_service_fee ⇒ Object
143 144 145 |
# File 'app/models/project.rb', line 143 def total_payment_service_fee project_total ? project_total.total_payment_service_fee : 0.0 end |
#update_video_embed_url ⇒ Object
191 192 193 |
# File 'app/models/project.rb', line 191 def self. = self.video. if self.video.present? end |
#video ⇒ Object
131 132 133 |
# File 'app/models/project.rb', line 131 def video @video ||= VideoInfo.get(self.video_url) if self.video_url.present? end |