Class: Effective::Event

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
PgSearch::Model
Defined in:
app/models/effective/event.rb

Instance Method Summary collapse

Instance Method Details

#any_waitlist?Boolean

Returns:

  • (Boolean)


189
190
191
# File 'app/models/effective/event.rb', line 189

def any_waitlist?
  event_tickets.any? { |et| et.waitlist? }
end

#bodyObject



181
182
183
# File 'app/models/effective/event.rb', line 181

def body
  rich_text_body
end

#closed?Boolean

Returns:

  • (Boolean)


201
202
203
204
# File 'app/models/effective/event.rb', line 201

def closed?
  return false if registration_end_at.blank?
  registration_end_at < Time.zone.now
end

#delayed?Boolean

Returns:

  • (Boolean)


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

def delayed?
  delayed_payment? && delayed_payment_date.present?
end

#delayed_payment_date_upcoming?Boolean

Returns:

  • (Boolean)


287
288
289
290
# File 'app/models/effective/event.rb', line 287

def delayed_payment_date_upcoming?
  return false unless delayed?
  delayed_payment_date > Time.zone.now.to_date
end

#duplicateObject

Returns a duplicated event object, or throws an exception



233
234
235
236
237
238
239
240
241
242
243
# File 'app/models/effective/event.rb', line 233

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



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

def duplicate!
  duplicate.tap { |event| event.save! }
end

#early_bird?Boolean

Returns:

  • (Boolean)


212
213
214
215
# File 'app/models/effective/event.rb', line 212

def early_bird?
  return false if early_bird_end_at.blank?
  early_bird_end_at > Time.zone.now
end

#early_bird_past?Boolean

Returns:

  • (Boolean)


217
218
219
220
# File 'app/models/effective/event.rb', line 217

def early_bird_past?
  return false if early_bird_end_at.blank?
  early_bird_end_at <= Time.zone.now
end

#early_bird_statusObject



222
223
224
225
226
227
228
229
230
# File 'app/models/effective/event.rb', line 222

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?

Returns:

  • (Boolean)


269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'app/models/effective/event.rb', line 269

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, quantity:) ⇒ Boolean

Can I register/purchase this many new event tickets?

Returns:

  • (Boolean)


254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'app/models/effective/event.rb', line 254

def event_ticket_available?(event_ticket, quantity:)
  raise('expected an EventTicket') unless event_ticket.kind_of?(Effective::EventTicket)
  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 for this ticket

  # Total number already sold
  registered = registered_event_registrants.count { |r| r.event_ticket_id == event_ticket.id }

  # If there's capacity for this many more
  (registered + quantity) <= event_ticket.capacity
end

#excerptObject



185
186
187
# File 'app/models/effective/event.rb', line 185

def excerpt
  rich_text_excerpt
end

#registerable?Boolean

Returns:

  • (Boolean)


193
194
195
196
197
198
199
# File 'app/models/effective/event.rb', line 193

def registerable?
  return false unless published?
  return false if closed?
  return false if sold_out?

  (external_registration? && external_registration_url.present?) || event_tickets.present?
end

#sold_out?Boolean

Returns:

  • (Boolean)


206
207
208
209
210
# File 'app/models/effective/event.rb', line 206

def sold_out?
  return false unless event_tickets.present?
  return false if any_waitlist?
  event_tickets.none? { |event_ticket| event_ticket_available?(event_ticket, quantity: 1) }
end

#start_timeObject



249
250
251
# File 'app/models/effective/event.rb', line 249

def start_time
  start_at
end

#to_sObject



177
178
179
# File 'app/models/effective/event.rb', line 177

def to_s
  title.presence || model_name.human
end