Class: Effective::EventRegistrant

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
app/models/effective/event_registrant.rb

Constant Summary collapse

PERMITTED_BLANK_REGISTRANT_CHANGES =
["first_name", "last_name", "email", "company", "user_id", "user_type", "organization_id", "organization_type", "blank_registrant", "response1", "response2", "response3"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#building_user_and_organizationObject

Returns the value of attribute building_user_and_organization.



11
12
13
# File 'app/models/effective/event_registrant.rb', line 11

def building_user_and_organization
  @building_user_and_organization
end

Instance Method Details

#archive!Object



338
339
340
341
342
# File 'app/models/effective/event_registrant.rb', line 338

def archive!
  super()
  orders.reject(&:purchased?).each { |order| order.update_purchasable_attributes! }
  true
end

#detailsObject



215
216
217
218
219
220
221
# File 'app/models/effective/event_registrant.rb', line 215

def details
  [
    ((:span, 'Member', class: 'badge badge-warning') if member_ticket?),
    ((:span, 'Waitlist', class: 'badge badge-warning') if waitlisted_not_promoted?),
    ((:span, 'Archived', class: 'badge badge-warning') if archived?)
  ].compact.join(' ').html_safe
end

#event_registration_submit_orderObject



380
381
382
# File 'app/models/effective/event_registrant.rb', line 380

def event_registration_submit_order
  event_registration&.submit_order
end

#event_ticket_priceObject



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'app/models/effective/event_registrant.rb', line 350

def event_ticket_price
  raise('expected an event') if event.blank?
  raise('expected an event ticket') if event_ticket.blank?

  if event.early_bird?
    event_ticket.early_bird_price # Early Bird Pricing
  elsif event_ticket.regular?
    event_ticket.regular_price
  elsif event_ticket.member_only?
    event_ticket.member_price
  elsif event_ticket.member_or_non_member?
    (member_present? ? event_ticket.member_price : event_ticket.regular_price)
  else
    raise("Unexpected event ticket price calculation")
  end
end

#full_nameObject

Used in email and tickets datatable



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'app/models/effective/event_registrant.rb', line 201

def full_name
  if first_name.present?
    [
      name,
      ("<small>#{organization || company}</small>" if organization || company.present?),
      ("<small>#{email}</small>" if email.present?)
    ].compact.join('<br>').html_safe
  elsif owner.present?
    owner.to_s + ' - GUEST'
  else
    'GUEST'
  end
end

#last_first_nameObject



231
232
233
# File 'app/models/effective/event_registrant.rb', line 231

def last_first_name
  (first_name.present? && last_name.present?) ? "#{last_name}, #{first_name}" : "GUEST"
end

#mark_registered!Object

This is the Admin Save and Mark Registered action



289
290
291
# File 'app/models/effective/event_registrant.rb', line 289

def mark_registered!
  registered!
end

#member_present?Boolean

Returns:

  • (Boolean)


245
246
247
# File 'app/models/effective/event_registrant.rb', line 245

def member_present?
  user.try(:membership_present?) || organization.try(:membership_present?)
end

#member_ticket?Boolean

Returns:

  • (Boolean)


249
250
251
252
253
254
255
# File 'app/models/effective/event_registrant.rb', line 249

def member_ticket?
  return false if event_ticket.blank?
  return true if event_ticket.member_only?
  return true if event_ticket.member_or_non_member? && member_present?

  false
end

#nameObject



190
191
192
193
194
195
196
197
198
# File 'app/models/effective/event_registrant.rb', line 190

def name
  if first_name.present?
    "#{first_name} #{last_name}"
  elsif owner.present?
    owner.to_s + ' - GUEST'
  else
    'GUEST'
  end
end

#present_registrant?Boolean

Returns:

  • (Boolean)


257
258
259
# File 'app/models/effective/event_registrant.rb', line 257

def present_registrant?
  !blank_registrant?
end

#promote!Object



320
321
322
323
324
325
326
327
# File 'app/models/effective/event_registrant.rb', line 320

def promote!
  raise('expected a waitlist? event_ticket') unless event_ticket.waitlist?

  update!(promoted: true)
  orders.reject(&:purchased?).each { |order| order.update_purchasable_attributes! }

  true
end

#purchasable_nameObject



227
228
229
# File 'app/models/effective/event_registrant.rb', line 227

def purchasable_name
  ["#{event_ticket} - #{name}", details.presence].compact.join('<br>').html_safe
end

#qb_item_nameObject



265
266
267
# File 'app/models/effective/event_registrant.rb', line 265

def qb_item_name
  event_ticket&.qb_item_name
end

#registered!Object

Called by an event_registration after_defer and after_purchase



283
284
285
286
# File 'app/models/effective/event_registrant.rb', line 283

def registered!
  self.registered_at ||= Time.zone.now
  save!
end

#registered?Boolean

Returns:

  • (Boolean)


273
274
275
# File 'app/models/effective/event_registrant.rb', line 273

def registered?
  registered_at.present?
end

#registrant_validations_enabled?Boolean

We create registrants on the tickets step. But don’t enforce validations until the details step.

Returns:

  • (Boolean)


236
237
238
239
240
241
242
243
# File 'app/models/effective/event_registrant.rb', line 236

def registrant_validations_enabled?
  return false if blank_registrant? # They want to come back later

  return true if event_registration.blank? # If we're creating in an Admin area
  return false if event_ticket.blank? # Invalid anyway

  event_registration.current_step == :details
end

#responsesObject



223
224
225
# File 'app/models/effective/event_registrant.rb', line 223

def responses
  [response1.presence, response2.presence, response3.presence].compact.join('<br>').html_safe
end

#save_and_update_orders!Object

Admin update event registrant action



294
295
296
297
298
299
300
# File 'app/models/effective/event_registrant.rb', line 294

def save_and_update_orders!
  save!

  orders.reject(&:purchased?).each { |order| order.update_purchasable_attributes! }

  true
end

#selected?Boolean

Returns:

  • (Boolean)


269
270
271
# File 'app/models/effective/event_registrant.rb', line 269

def selected?
  selected_at.present?
end

#selected_not_expired?Boolean

Returns:

  • (Boolean)


277
278
279
280
# File 'app/models/effective/event_registrant.rb', line 277

def selected_not_expired?
  return false unless EffectiveEvents.EventRegistration.selection_window.present?
  selected_at.present? && (selected_at + EffectiveEvents.EventRegistration.selection_window > Time.zone.now)
end

#send_confirmation_email!Object

Manual admin action only



372
373
374
# File 'app/models/effective/event_registrant.rb', line 372

def send_confirmation_email!
  send_order_emails!
end

#send_order_emails!Object



376
377
378
# File 'app/models/effective/event_registrant.rb', line 376

def send_order_emails!
  event_registration&.submit_order&.send_order_emails!
end

#tax_exemptObject



261
262
263
# File 'app/models/effective/event_registrant.rb', line 261

def tax_exempt
  event_ticket&.tax_exempt
end

#titleObject



186
187
188
# File 'app/models/effective/event_registrant.rb', line 186

def title
  ["#{event_ticket} - #{name}", details.presence].compact.join(' ').html_safe
end

#to_sObject



182
183
184
# File 'app/models/effective/event_registrant.rb', line 182

def to_s
  persisted? ? title : 'registrant'
end

#unarchive!Object



344
345
346
347
348
# File 'app/models/effective/event_registrant.rb', line 344

def unarchive!
  super()
  orders.reject(&:purchased?).each { |order| order.update_purchasable_attributes! }
  true
end

#unpromote!Object



329
330
331
332
333
334
335
336
# File 'app/models/effective/event_registrant.rb', line 329

def unpromote!
  raise('expected a waitlist? event_ticket') unless event_ticket.waitlist?

  update!(promoted: false)
  orders.reject(&:purchased?).each { |order| order.update_purchasable_attributes! }

  true
end

#unwaitlist!Object



311
312
313
314
315
316
317
318
# File 'app/models/effective/event_registrant.rb', line 311

def unwaitlist!
  raise('expected a waitlist? event_ticket') unless event_ticket.waitlist?

  update!(waitlisted: false)
  orders.reject(&:purchased?).each { |order| order.update_purchasable_attributes! }

  true
end

#waitlist!Object



302
303
304
305
306
307
308
309
# File 'app/models/effective/event_registrant.rb', line 302

def waitlist!
  raise('expected a waitlist? event_ticket') unless event_ticket.waitlist?

  update!(waitlisted: true)
  orders.reject(&:purchased?).each { |order| order.update_purchasable_attributes! }

  true
end

#waitlisted_not_promoted?Boolean

Returns:

  • (Boolean)


367
368
369
# File 'app/models/effective/event_registrant.rb', line 367

def waitlisted_not_promoted?
  (waitlisted? && !promoted?)
end