Class: Effective::Event
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::Event
- Includes:
- PgSearch::Model
- Defined in:
- app/models/effective/event.rb
Instance Method Summary collapse
- #any_waitlist? ⇒ Boolean
- #body ⇒ Object
-
#capacity_available(event_ticket:, event_registration: nil) ⇒ Object
The amount of tickets that can be purchased except ones from an event registration.
-
#capacity_selectable(event_ticket:, event_registration: nil) ⇒ Object
The amount of tickets that can be purchased except ones from an event registration.
-
#capacity_taken(event_ticket:, event_registration: nil) ⇒ Object
Just used in tests so far.
- #closed? ⇒ Boolean
- #delayed? ⇒ Boolean
- #delayed_payment_date_upcoming? ⇒ Boolean
-
#duplicate ⇒ Object
Returns a duplicated event object, or throws an exception.
- #duplicate! ⇒ Object
- #early_bird? ⇒ Boolean
- #early_bird_past? ⇒ Boolean
- #early_bird_status ⇒ Object
-
#event_product_available?(event_product, quantity:) ⇒ Boolean
Can I register/purchase this many new event products?.
-
#event_ticket_available?(event_ticket, except: nil, quantity: 0) ⇒ Boolean
Can I register/purchase this many new event tickets?.
- #excerpt ⇒ Object
-
#registerable? ⇒ Boolean
No longer includes sold_out? we check that separately.
- #sold_out?(except: nil) ⇒ Boolean
- #start_time ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#any_waitlist? ⇒ Boolean
189 190 191 |
# File 'app/models/effective/event.rb', line 189 def any_waitlist? event_tickets.any? { |et| et.waitlist? } end |
#body ⇒ Object
181 182 183 |
# File 'app/models/effective/event.rb', line 181 def body rich_text_body end |
#capacity_available(event_ticket:, event_registration: nil) ⇒ Object
The amount of tickets that can be purchased except ones from an event registration
265 266 267 |
# File 'app/models/effective/event.rb', line 265 def capacity_available(event_ticket:, event_registration: nil) event_ticket.capacity_available(except: event_registration) end |
#capacity_selectable(event_ticket:, event_registration: nil) ⇒ Object
The amount of tickets that can be purchased except ones from an event registration
256 257 258 259 260 261 262 |
# File 'app/models/effective/event.rb', line 256 def capacity_selectable(event_ticket:, event_registration: nil) return 0 if event_ticket.archived? return 100 if event_ticket.capacity.blank? return 100 if event_ticket.waitlist? event_ticket.capacity_selectable(except: event_registration) end |
#capacity_taken(event_ticket:, event_registration: nil) ⇒ Object
Just used in tests so far
270 271 272 |
# File 'app/models/effective/event.rb', line 270 def capacity_taken(event_ticket:, event_registration: nil) event_ticket.capacity_taken(except: event_registration) end |
#closed? ⇒ Boolean
200 201 202 203 |
# File 'app/models/effective/event.rb', line 200 def closed? return false if registration_end_at.blank? registration_end_at < Time.zone.now end |
#delayed? ⇒ Boolean
303 304 305 |
# File 'app/models/effective/event.rb', line 303 def delayed? delayed_payment? && delayed_payment_date.present? end |
#delayed_payment_date_upcoming? ⇒ Boolean
307 308 309 310 |
# File 'app/models/effective/event.rb', line 307 def delayed_payment_date_upcoming? return false unless delayed? delayed_payment_date > Time.zone.now.to_date end |
#duplicate ⇒ Object
Returns a duplicated event object, or throws an exception
235 236 237 238 239 240 241 242 243 244 245 |
# File 'app/models/effective/event.rb', line 235 def duplicate Event.new(attributes.except('id', 'updated_at', 'created_at')).tap do |event| event.title = event.title + ' (Copy)' event.slug = event.slug + '-copy' event.rich_text_body = rich_text_body event.rich_text_excerpt = rich_text_excerpt event.assign_attributes(published_start_at: nil, published_end_at: nil) end end |
#duplicate! ⇒ Object
247 248 249 |
# File 'app/models/effective/event.rb', line 247 def duplicate! duplicate.tap { |event| event.save! } end |
#early_bird? ⇒ Boolean
214 215 216 217 |
# File 'app/models/effective/event.rb', line 214 def early_bird? return false if early_bird_end_at.blank? early_bird_end_at > Time.zone.now end |
#early_bird_past? ⇒ Boolean
219 220 221 222 |
# File 'app/models/effective/event.rb', line 219 def early_bird_past? return false if early_bird_end_at.blank? early_bird_end_at <= Time.zone.now end |
#early_bird_status ⇒ Object
224 225 226 227 228 229 230 231 232 |
# File 'app/models/effective/event.rb', line 224 def early_bird_status if early_bird? 'Early Bird Pricing' elsif early_bird_past? 'Expired' else 'None' end end |
#event_product_available?(event_product, quantity:) ⇒ Boolean
Can I register/purchase this many new event products?
289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'app/models/effective/event.rb', line 289 def event_product_available?(event_product, quantity:) raise('expected an EventProduct') unless event_product.kind_of?(Effective::EventProduct) raise('expected quantity to be greater than 0') unless quantity.to_i > 0 return false if event_product.archived? return true if event_product.capacity.blank? # No capacity enforced for this product # Total number already sold registered = registered_event_addons.count { |r| r.event_product_id == event_product.id } # If there's capacity for this many more (registered + quantity) <= event_product.capacity end |
#event_ticket_available?(event_ticket, except: nil, quantity: 0) ⇒ Boolean
Can I register/purchase this many new event tickets?
275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'app/models/effective/event.rb', line 275 def event_ticket_available?(event_ticket, except: nil, quantity: 0) raise('expected an EventTicket') unless event_ticket.kind_of?(Effective::EventTicket) raise('expected except to be an EventRegistration') if except && !except.class.try(:effective_events_event_registration?) raise('expected quantity to be greater than 0') unless quantity.to_i > 0 return false if event_ticket.archived? return true if event_ticket.capacity.blank? # No capacity enforced return true if event_ticket.waitlist? # Always available for waitlist # Do we have any tickets available left? event_ticket.capacity_available(except: except) >= quantity.to_i end |
#excerpt ⇒ Object
185 186 187 |
# File 'app/models/effective/event.rb', line 185 def excerpt rich_text_excerpt end |
#registerable? ⇒ Boolean
No longer includes sold_out? we check that separately
194 195 196 197 198 |
# File 'app/models/effective/event.rb', line 194 def registerable? return false unless published? return false if closed? (external_registration? && external_registration_url.present?) || event_tickets.present? end |
#sold_out?(except: nil) ⇒ Boolean
205 206 207 208 209 210 211 212 |
# File 'app/models/effective/event.rb', line 205 def sold_out?(except: nil) raise('expected except to be an EventRegistration') if except && !except.class.try(:effective_events_event_registration?) return false unless event_tickets.present? return false if any_waitlist? event_tickets.none? { |event_ticket| event_ticket_available?(event_ticket, except: except, quantity: 1) } end |
#start_time ⇒ Object
251 252 253 |
# File 'app/models/effective/event.rb', line 251 def start_time start_at end |
#to_s ⇒ Object
177 178 179 |
# File 'app/models/effective/event.rb', line 177 def to_s title.presence || model_name.human end |