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



229
230
231
232
233
234
235
# File 'app/models/concerns/effective_events_event_registration.rb', line 229

def addons!
  after_commit do
    update_submit_fees_and_order! if submit_order.present?
  end

  save!
end

#build_event_addonsObject

This builds the default event addons used by the wizard form



279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'app/models/concerns/effective_events_event_registration.rb', line 279

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_registrantsObject

This builds the default event registrants used by the wizard form



268
269
270
271
272
273
274
275
276
# File 'app/models/concerns/effective_events_event_registration.rb', line 268

def build_event_registrants
  if event_registrants.blank?
    raise('expected owner and event to be present') unless owner && event

    event_registrants.build()
  end

  event_registrants
end

#complete!Object



243
244
245
246
247
248
249
250
251
252
253
# File 'app/models/concerns/effective_events_event_registration.rb', line 243

def complete!
  raise('event registration must be submitted to complete!') unless 
  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

#done?Boolean

Returns:

  • (Boolean)


216
217
218
# File 'app/models/concerns/effective_events_event_registration.rb', line 216

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.



262
263
264
265
# File 'app/models/concerns/effective_events_event_registration.rb', line 262

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_registrant(event_ticket:, first_name:, last_name:, email:) ⇒ Object

Find or build



256
257
258
259
# File 'app/models/concerns/effective_events_event_registration.rb', line 256

def event_registrant(event_ticket:, first_name:, last_name:, email:)
  registrant = event_registrants.find { |er| er.event_ticket == event_ticket && er.first_name == first_name && er.last_name == last_name && er.email == email }
  registrant || event_registrants.build(event: event, event_ticket: event_ticket, owner: owner, first_name: first_name, last_name: last_name, email: email)
end

#event_ticket_member_usersObject



319
320
321
322
323
324
# File 'app/models/concerns/effective_events_event_registration.rb', line 319

def event_ticket_member_users
  raise("expected owner to be a user") if owner.class.try(:effective_memberships_organization?)
  users = [owner] + (owner.try(:organizations).try(:flat_map, &:users) || [])

  users.select { |user| user.is_any?(:member) }.uniq
end

#event_ticketsObject



293
294
295
# File 'app/models/concerns/effective_events_event_registration.rb', line 293

def event_tickets
  present_event_registrants.map(&:event_ticket).uniq
end

#in_progress?Boolean

Returns:

  • (Boolean)


212
213
214
# File 'app/models/concerns/effective_events_event_registration.rb', line 212

def in_progress?
  draft? || 
end

#tickets!Object



220
221
222
223
224
225
226
227
# File 'app/models/concerns/effective_events_event_registration.rb', line 220

def tickets!
  after_commit do
    update_submit_fees_and_order! if submit_order.present?
    update_deferred_event_registration! if submit_order&.deferred?
  end

  save!
end

#to_sObject

Instance Methods



208
209
210
# File 'app/models/concerns/effective_events_event_registration.rb', line 208

def to_s
  'registration'
end

#try_completed!Object



237
238
239
240
241
# File 'app/models/concerns/effective_events_event_registration.rb', line 237

def try_completed!
  return false unless 
  return false unless submit_order&.purchased?
  complete!
end

#unavailable_event_productsObject



309
310
311
312
313
314
315
316
317
# File 'app/models/concerns/effective_events_event_registration.rb', line 309

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_ticketsObject



297
298
299
300
301
302
303
304
305
306
307
# File 'app/models/concerns/effective_events_event_registration.rb', line 297

def unavailable_event_tickets
  unavailable = []

  present_event_registrants.map(&:event_ticket).group_by { |t| t }.each do |event_ticket, event_tickets|
    unless event_ticket.waitlist? || event.event_ticket_available?(event_ticket, quantity: event_tickets.length)
      unavailable << event_ticket 
    end
  end

  unavailable
end

#update_blank_registrants!Object



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'app/models/concerns/effective_events_event_registration.rb', line 326

def update_blank_registrants!
  # This method is called by the user on a submitted or completed event registration.
  # Allow them to update blank registrants
  # Don't let them hack the form and change any information.
  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

  save!

  update_submit_fees_and_order! if submit_order.present? && !submit_order.purchased?

  true
end