Module: EffectiveEventsEventRegistration
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_events_event_registration.rb
Overview
EffectiveEventsEventRegistration
Mark your owner model with effective_events_event_registration to get all the includes
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary
collapse
Instance Method Details
#addons! ⇒ Object
333
334
335
336
337
338
339
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 333
def addons!
after_commit do
update_submit_fees_and_order! if submit_order.present?
end
save!
end
|
#build_event_addons ⇒ Object
This builds the default event addons used by the wizard form
382
383
384
385
386
387
388
389
390
391
392
393
394
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 382
def build_event_addons
if event_addons.blank?
raise('expected owner and event to be present') unless owner && event
event_addons.build(
first_name: owner.try(:first_name),
last_name: owner.try(:last_name),
email: owner.try(:email)
)
end
event_addons
end
|
#build_event_registrant(event_ticket:) ⇒ Object
359
360
361
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 359
def build_event_registrant(event_ticket:)
event_registrants.build(event: event, event_ticket: event_ticket, owner: owner)
end
|
#complete! ⇒ Object
347
348
349
350
351
352
353
354
355
356
357
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 347
def complete!
raise('event registration must be submitted to complete!') unless submitted?
raise('expected a purchased order') unless submit_order&.purchased?
wizard_steps[:checkout] ||= Time.zone.now
wizard_steps[:submitted] ||= Time.zone.now
wizard_steps[:complete] = Time.zone.now
completed!
true
end
|
#display_countdown? ⇒ Boolean
234
235
236
237
238
239
240
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 234
def display_countdown?
return false if done?
return false unless selected_at.present?
return false unless current_step.present?
[:start, :tickets, :submitted, :complete].exclude?(current_step)
end
|
#done? ⇒ Boolean
230
231
232
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 230
def done?
completed?
end
|
#event_addon(event_product:, first_name:, last_name:, email:) ⇒ Object
Find or build. But it’s not gonna work with more than 1. This is for testing only really.
370
371
372
373
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 370
def event_addon(event_product:, first_name:, last_name:, email:)
addon = event_addons.find { |er| er.event_product == event_product && er.first_name == first_name && er.last_name == last_name && er.email == email }
addon || event_addons.build(event: event, event_product: event_product, owner: owner, first_name: first_name, last_name: last_name, email: email)
end
|
#event_ticket_selection(event_ticket:, quantity: 0) ⇒ Object
376
377
378
379
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 376
def event_ticket_selection(event_ticket:, quantity: 0)
selection = event_ticket_selections.find { |ets| ets.event_ticket == event_ticket }
selection || event_ticket_selections.build(event_ticket: event_ticket, quantity: quantity)
end
|
#event_tickets ⇒ Object
396
397
398
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 396
def event_tickets
present_event_registrants.map(&:event_ticket).uniq
end
|
#in_progress? ⇒ Boolean
226
227
228
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 226
def in_progress?
draft? || submitted?
end
|
#select_event_registrants ⇒ Object
Assigns the selected at time to start the reservation window
299
300
301
302
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 299
def select_event_registrants
now = Time.zone.now
present_event_registrants.each { |er| er.assign_attributes(selected_at: now) }
end
|
#selected_at ⇒ Object
When we make a ticket selection, we assign the selected_at to all tickets So the max or the min should be the same here.
244
245
246
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 244
def selected_at
event_registrants.map(&:selected_at).compact.max
end
|
#selected_expired? ⇒ Boolean
252
253
254
255
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 252
def selected_expired?
return false if selected_at.blank?
Time.zone.now >= selected_expires_at
end
|
#selected_expires_at ⇒ Object
248
249
250
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 248
def selected_expires_at
selected_at + EffectiveEvents.EventRegistration.selection_window
end
|
#selection_not_expired? ⇒ Boolean
257
258
259
260
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 257
def selection_not_expired?
return true if selected_at.blank?
Time.zone.now < selected_expires_at
end
|
#ticket_selection_expired! ⇒ Object
Called by a before_action on the event registration show action
263
264
265
266
267
268
269
270
271
272
273
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 263
def ticket_selection_expired!
raise("unexpected submitted registration") if was_submitted?
raise("unexpected purchased order") if submit_order&.purchased?
raise("unexpected deferred order") if submit_order&.deferred?
event_registrants.each { |er| er.assign_attributes(selected_at: nil) }
event_ticket_selections.each { |ets| ets.assign_attributes(quantity: 0) }
assign_attributes(current_step: nil, wizard_steps: {})
save!
end
|
#tickets! ⇒ Object
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 316
def tickets!
assign_attributes(current_step: :tickets)
reset_all_wizard_steps_after(:tickets) unless was_submitted?
update_event_registrants
select_event_registrants
waitlist_event_registrants
after_commit do
update_submit_fees_and_order! if submit_order.present?
update_deferred_event_registration! if submit_order&.deferred?
end
save!
end
|
#to_s ⇒ Object
222
223
224
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 222
def to_s
'registration'
end
|
#try_completed! ⇒ Object
341
342
343
344
345
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 341
def try_completed!
return false unless submitted?
return false unless submit_order&.purchased?
complete!
end
|
#unavailable_event_products ⇒ Object
410
411
412
413
414
415
416
417
418
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 410
def unavailable_event_products
unavailable = []
present_event_addons.map(&:event_product).group_by { |p| p }.each do |event_product, event_products|
unavailable << event_product unless event.event_product_available?(event_product, quantity: event_products.length)
end
unavailable
end
|
#unavailable_event_tickets ⇒ Object
400
401
402
403
404
405
406
407
408
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 400
def unavailable_event_tickets
unavailable = []
present_event_registrants.map(&:event_ticket).group_by { |t| t }.each do |event_ticket, event_tickets|
unavailable << event_ticket unless event.event_ticket_available?(event_ticket, except: self, quantity: event_tickets.length)
end
unavailable
end
|
#update_blank_registrants! ⇒ Object
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 420
def update_blank_registrants!
if changes.present? || previous_changes.present?
raise('unable to make changes to event while updating blank registrants')
end
if event_registrants.any? { |er| (er.changes.keys - Effective::EventRegistrant::PERMITTED_BLANK_REGISTRANT_CHANGES).present? }
raise('unable to make changes to event registrants while updating blank registrants')
end
if event_registrants.any? { |er| er.blank_registrant_was == false && er.changes.present? }
raise('unable to make changes to non-blank registrant while updating blank registrants')
end
if event_addons.any? { |ea| ea.changes.present? }
raise('unable to make changes to event addons while updating blank registrants')
end
assign_attributes(current_step: :details) if current_step.blank? save!
update_submit_fees_and_order! if submit_order.present? && !submit_order.purchased?
true
end
|
#update_event_registrants ⇒ Object
This considers the event_ticket_selection and builds the appropriate event_registrants
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 276
def update_event_registrants
event_ticket_selections.each do |event_ticket_selection|
event_ticket = event_ticket_selection.event_ticket
quantity = event_ticket_selection.quantity.to_i
registrants = event_registrants.select { |er| er.event_ticket == event_ticket }
if (diff = registrants.length - quantity) > 0
registrants.last(diff).each { |er| er.mark_for_destruction }
end
if (diff = quantity - registrants.length) > 0
diff.times { build_event_registrant(event_ticket: event_ticket) }
end
end
event_registrants
end
|
#waitlist_event_registrants ⇒ Object
Looks at any unselected event registrants and assigns a waitlist value
305
306
307
308
309
310
311
312
313
314
|
# File 'app/models/concerns/effective_events_event_registration.rb', line 305
def waitlist_event_registrants
present_event_registrants.group_by { |er| er.event_ticket }.each do |event_ticket, event_registrants|
if event_ticket.waitlist?
capacity = event.capacity_available(event_ticket: event_ticket, event_registration: self)
event_registrants.each_with_index { |er, index| er.assign_attributes(waitlisted: index >= capacity) }
else
event_registrants.each { |er| er.assign_attributes(waitlisted: false) }
end
end
end
|